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 Stringstatic StringfixCapitalization(String string) Capitalises the first character of the string and all characters that follow periods, exclamation and question marks.static byte[]static intReturns the index of the first occurrence of the needle in the haystack.static intReturns the index of the first occurrence of the needle in the haystack, starting from the specified index.static intindexOfOutsideGroup(String string, char find, char groupOpen, char groupClose, int i) static Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic StringJoin elements with delimiter except last one will be joined with lastDelimiter.static intlastIndexOf(String haystack, String needle, boolean caseSensitive) Returns the index of the last occurrence of the needle in the haystack.static 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, Function<Matcher, String> callback) Performs regex replacing using a callback.static @Nullable StringreplaceAll(CharSequence string, Pattern regex, Function<Matcher, String> 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
@Nullable public static @Nullable String replaceAll(CharSequence string, String regex, Function<Matcher, String> callback) Performs regex replacing using a callback.- Parameters:
string- the String in which should be searched invalid input: '&' 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
@Nullable public static @Nullable String replaceAll(CharSequence string, Pattern regex, Function<Matcher, String> callback) Performs regex replacing using a callback.- Parameters:
string- the String in which should be searched invalid input: '&' 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:
-
indexOf
Returns the index of the first occurrence of the needle in the haystack.- Parameters:
haystack- the string to search inneedle- the string to search forcaseSensitive- whether the search should be case-sensitive- Returns:
- the index of the first occurrence of the needle in the haystack, or -1 if not found
-
indexOf
Returns the index of the first occurrence of the needle in the haystack, starting from the specified index.- Parameters:
haystack- the string to search inneedle- the string to search forfromIndex- the index to start searching fromcaseSensitive- whether the search should be case-sensitive- Returns:
- the index of the first occurrence of the needle in the haystack, or -1 if not found
-
lastIndexOf
Returns the index of the last occurrence of the needle in the haystack.- Parameters:
haystack- the string to search inneedle- the string to search forcaseSensitive- whether the search should be case-sensitive- Returns:
- the index of the last occurrence of the needle in the haystack, or -1 if not found
-
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
-
join
public static String join(@Nullable @Nullable Iterator<?> strings, String delimiter, String lastDelimiter) Join elements with delimiter except last one will be joined with lastDelimiter.- Parameters:
strings- The strings to joindelimiter- The delimiter to use between all elements except the last onelastDelimiter- The delimiter to use between the last two elements- Returns:
- The joined string
-
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)
-