Class StringUtils

java.lang.Object
io.github.syst3ms.skriptparser.util.StringUtils

public class StringUtils extends Object
Utility functions for strings
  • Field Details

    • R_LITERAL_CONTENT_PATTERN

      public static final Pattern R_LITERAL_CONTENT_PATTERN
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • count

      public static int count(String s, String... toFind)
      Counts combined occurrences of one or more strings in another
      Parameters:
      s - the string to find occurrences in
      toFind - the strings to find occurrences of
      Returns:
      the amount of total occurrences
    • findClosingIndex

      public static int findClosingIndex(String pattern, char opening, char closing, int start)
      Find where a given pair of braces closes.
      Parameters:
      pattern - the string to look in
      opening - the opening brace
      closing - the closing brace
      start - where the brace pair starts
      Returns:
      the index at which the brace pair closes
    • getEnclosedText

      public static Optional<String> getEnclosedText(String pattern, char opening, char closing, int start)
      Similar to findClosingIndex(String, char, char, int), but returns the enclosed text
      Parameters:
      pattern - the string to look in
      opening - the opening brace
      closing - the closing brace
      start - where the brace pair starts
      Returns:
      the enclosed text
    • nextSimpleCharacterIndex

      public static int nextSimpleCharacterIndex(String s, int index)
      Returns the next character in the string, skipping over curly braces and string literals
      Parameters:
      s - the string to search
      index - the current index
      Returns:
      the index of the next "simple" character, or -1 if the end of the string has been reached
      Throws:
      StringIndexOutOfBoundsException - if index < 0
    • getPercentContent

      public static Optional<String> getPercentContent(String s, int start)
      Finds the contents of an expression between %%
      Parameters:
      s - the string containing the percents
      start - where the pair begins
      Returns:
      the content between %%
    • getBracketContent

      public static Optional<String> getBracketContent(String s, int start, char closingBracket)
      Finds the contents until a closing bracket is found
      Parameters:
      s - the string containing the percents
      start - where the pair begins
      closingBracket - the closing bracket
      Returns:
      the content until the closing bracket
    • indexOfIgnoreCase

      public static int indexOfIgnoreCase(String haystack, String needle, int start)
      Find the first occurrence of a string in another one, ignoring case
      Parameters:
      haystack - the string to look in
      needle - the string to look for
      start - where to look from
      Returns:
      the index of the first occurrence
    • splitVerticalBars

      public static Optional<String[]> splitVerticalBars(String s, SkriptLogger logger)
      Split a pattern at pipe characters, properly accounting for brackets and escapes
      Parameters:
      s - the string to split
      logger - the logger
      Returns:
      the split string
    • getForms

      public static String[] getForms(String pluralizable)
      Returns an array of two elements, containing the plural and singular forms of the given pluralizable expression. Does not support escaping.
    • withIndefiniteArticle

      public static String withIndefiniteArticle(String noun, boolean plural)
      Adds a proper English indefinite article to a string
      Parameters:
      noun - the string
      plural - whether it is plural or not
      Returns:
      the string with its proper indefinite article
    • toTitleCase

      public static String toTitleCase(String str, boolean allWords)
      Capitalizes the first word or all words in a string. A word is separated by a space character.
      Parameters:
      str - the string to change
      Returns:
      the capitalized string
    • toCamelCase

      public static String toCamelCase(String str, boolean firstNoCase)
    • toSnakeCase

      public static String toSnakeCase(String str, int mode)
      Converts a string into snake case.
      Parameters:
      str - the string to convert
      mode - 0 for default mode, 1 for uppercase and 2 for lowercase
      Returns:
      the converted string
    • toKebabCase

      public static String toKebabCase(String str, int mode)
      Converts a string into kebab case.
      Parameters:
      str - the string to convert
      mode - 0 for default mode, 1 for uppercase and 2 for lowercase
      Returns:
      the converted string
    • toReversedCase

      public static String toReversedCase(String str)
      Replaces all uppercase characters with lower case ones and vice versa.
      Parameters:
      str - the string to change
      Returns:
      the reversed string
    • mirrored

      public static String mirrored(String str)
      Mirrors the string. This means the last character will be put first and vice versa.
      Parameters:
      str - the string to change
      Returns:
      the mirrored string