Package ch.njol.util

Class StringUtils

java.lang.Object
ch.njol.util.StringUtils

public abstract class StringUtils extends Object
  • Constructor Details Link icon

    • StringUtils Link icon

      public StringUtils()
  • Method Details Link icon

    • checkIndices Link icon

      public static void checkIndices(String s, int start, int end)
    • fancyOrderNumber Link icon

      public static String fancyOrderNumber(int i)
      Appends the english order suffix to the given number.
      Parameters:
      i - the number
      Returns:
      1st, 2nd, 3rd, 4th, etc.
    • replaceAll Link icon

      @Nullable public static @Nullable String replaceAll(CharSequence string, String regex, Callback<String,Matcher> callback)
      Performs regex replacing using a callback.
      Parameters:
      string - the String in which should be searched invalid input: '&' replaced
      regex - the Regex to match
      callback - the callback will be run for every match of the regex in the string, and should return the replacement string for the given match. If the callback returns null for any given match this function will immediately terminate and return null.
      Returns:
    • replaceAll Link icon

      @Nullable public static @Nullable String replaceAll(CharSequence string, Pattern regex, Callback<String,Matcher> callback)
      Performs regex replacing using a callback.
      Parameters:
      string - the String in which should be searched invalid input: '&' replaced
      regex - the Regex to match
      callback - the callback will be run for every match of the regex in the string, and should return the replacement string for the given match. If the callback returns null for any given match this function will immediately terminate and return null.
      Returns:
    • count Link icon

      public static int count(String s, char c)
    • count Link icon

      public static int count(String s, char c, int start)
    • count Link icon

      public static int count(String s, char c, int start, int end)
    • contains Link icon

      public static boolean contains(String s, char c, int start, int end)
    • toString Link icon

      public static String toString(double d, int accuracy)
      Gets a rounded english (##.##) representation of a number
      Parameters:
      d - The number to be turned into a string
      accuracy - Maximum number of digits after the period
      Returns:
    • firstToUpper Link icon

      public static String firstToUpper(String s)
    • substring Link icon

      public static String substring(String s, int start, int end)
      Equal to String.substring(int, int), but allows negative indices that are counted from the end of the string.
      Parameters:
      s -
      start -
      end -
      Returns:
    • fixCapitalization Link icon

      public static String fixCapitalization(String string)
      Capitalises the first character of the string and all characters that follow periods, exclamation and question marks.
      Parameters:
      string -
      Returns:
    • numberAfter Link icon

      public static double numberAfter(CharSequence s, int index)
      Shorthand for numberAt(s, index, true)
      Parameters:
      s -
      index -
      Returns:
    • numberBefore Link icon

      public static double numberBefore(CharSequence s, int index)
      Shorthand for numberAt(s, index, false)
      Parameters:
      s -
      index -
      Returns:
    • numberAt Link icon

      public static double numberAt(CharSequence s, int index, boolean forward)
      Finds a positive number in the given CharSequence, starting at the given index, and searching in the given direction.

      The number has to start exactly at the given index (ignoring whitespace), and will only count if the other end of the number is either at an end of the string or padded by whitespace.

      Parameters:
      s - The ChatSequence to search the number in
      index - The index to start searching at (inclusive)
      forward - Whether to search forwards or backwards
      Returns:
      The number found or -1 if no matching number was found
    • startsWithIgnoreCase Link icon

      public static boolean startsWithIgnoreCase(String string, String start)
    • startsWithIgnoreCase Link icon

      public static boolean startsWithIgnoreCase(String string, String start, int offset)
    • endsWithIgnoreCase Link icon

      public static boolean endsWithIgnoreCase(String string, String end)
    • multiply Link icon

      public static String multiply(@Nullable @Nullable String s, int amount)
    • multiply Link icon

      public static String multiply(char c, int amount)
    • join Link icon

      public static String join(@Nullable @Nullable Object[] strings)
    • join Link icon

      public static String join(@Nullable @Nullable Object[] strings, String delimiter)
    • join Link icon

      public static String join(@Nullable @Nullable Object[] strings, String delimiter, int start, int end)
    • join Link icon

      public static String join(@Nullable @Nullable Iterable<?> strings)
    • join Link icon

      public static String join(@Nullable @Nullable Iterable<?> strings, String delimiter)
    • join Link icon

      public static String join(@Nullable @Nullable Iterator<?> strings, String delimiter)
    • findLastDigit Link icon

      public static int findLastDigit(String s, int start)
      Scans the string starting at start for digits.
      Parameters:
      s -
      start - Index of the first digit
      Returns:
      The index after the last digit or start if there are no digits at the given index
    • containsAny Link icon

      public static boolean containsAny(String s, String chars)
      Searches for whether a String contains any of the characters of another string.
      Parameters:
      s -
      chars -
      Returns:
    • equals Link icon

      public static boolean equals(String s1, String s2, boolean caseSensitive)
    • contains Link icon

      public static boolean contains(String haystack, String needle, boolean caseSensitive)
    • replace Link icon

      public static String replace(String haystack, String needle, String replacement, boolean caseSensitive)
    • replaceFirst Link icon

      public static String replaceFirst(String haystack, String needle, String replacement, boolean caseSensitive)
    • hexStringToByteArray Link icon

      public static byte[] hexStringToByteArray(String s)
    • indexOfOutsideGroup Link icon

      public static int indexOfOutsideGroup(String string, char find, char groupOpen, char groupClose, int i)