Package ch.njol.util
Class StringUtils
java.lang.Object
ch.njol.util.StringUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckIndices(String s, int start, int end)static booleanstatic booleanstatic booleancontainsAny(String s, String chars)Searches for whether a String contains any of the characters of another string.static intstatic intstatic intstatic booleanendsWithIgnoreCase(String string, String end)static booleanstatic StringfancyOrderNumber(int i)Appends the english order suffix to the given number.static intfindLastDigit(String s, int start)Scans the string starting at start for digits.static StringfirstToUpper(String s)static StringfixCapitalization(String string)Capitalises the first character of the string and all characters that follow periods, exclamation and question marks.static byte[]static intindexOfOutsideGroup(String string, char find, char groupOpen, char groupClose, int i)static Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic Stringmultiply(char c, int amount)static Stringstatic doublenumberAfter(CharSequence s, int index)Shorthand fornumberAt(s, index, true)static doublenumberAt(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.static doublenumberBefore(CharSequence s, int index)Shorthand fornumberAt(s, index, false)static Stringstatic @Nullable StringreplaceAll(CharSequence string, String regex, Callback<String,Matcher> callback)Performs regex replacing using a callback.static @Nullable StringreplaceAll(CharSequence string, Pattern regex, Callback<String,Matcher> callback)Performs regex replacing using a callback.static StringreplaceFirst(String haystack, String needle, String replacement, boolean caseSensitive)static booleanstartsWithIgnoreCase(String string, String start)static booleanstartsWithIgnoreCase(String string, String start, int offset)static StringEqual toString.substring(int, int), but allows negative indices that are counted from the end of the string.static StringtoString(double d, int accuracy)Gets a rounded english (##.##) representation of a number
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
checkIndices
-
fancyOrderNumber
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 & replacedregex- the Regex to matchcallback- 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 & replacedregex- the Regex to matchcallback- 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
-
count
-
count
-
contains
-
toString
Gets a rounded english (##.##) representation of a number- Parameters:
d- The number to be turned into a stringaccuracy- Maximum number of digits after the period- Returns:
-
firstToUpper
-
substring
Equal toString.substring(int, int), but allows negative indices that are counted from the end of the string.- Parameters:
s-start-end-- Returns:
-
fixCapitalization
Capitalises the first character of the string and all characters that follow periods, exclamation and question marks.- Parameters:
string-- Returns:
-
numberAfter
Shorthand fornumberAt(s, index, true)- Parameters:
s-index-- Returns:
-
numberBefore
Shorthand fornumberAt(s, index, false)- Parameters:
s-index-- Returns:
-
numberAt
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 inindex- 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
-
startsWithIgnoreCase
-
endsWithIgnoreCase
-
multiply
-
multiply
-
join
-
join
-
join
-
join
-
join
-
join
-
findLastDigit
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
Searches for whether a String contains any of the characters of another string.- Parameters:
s-chars-- Returns:
-
equals
-
contains
-
replace
-
replaceFirst
-
hexStringToByteArray
-
indexOfOutsideGroup
public static int indexOfOutsideGroup(String string, char find, char groupOpen, char groupClose, int i)
-