Package ch.njol.util

Class StringUtils

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

public abstract class StringUtils extends Object
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • checkIndices

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

      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

      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 & 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

      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 & 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

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

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

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

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

      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

      public static String firstToUpper(String s)
    • substring

      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

      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

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

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

      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

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

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

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

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

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

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

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

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

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

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

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

      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

      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

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

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

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

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

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

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