Package ch.njol.util
Class StringUtils
java.lang.Object
ch.njol.util.StringUtils
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkIndices(String s, int start, int end)
static boolean
static boolean
static boolean
containsAny(String s, String chars)
Searches for whether a String contains any of the characters of another string.static int
static int
static int
static boolean
endsWithIgnoreCase(String string, String end)
static boolean
static String
fancyOrderNumber(int i)
Appends the english order suffix to the given number.static int
findLastDigit(String s, int start)
Scans the string starting at start for digits.static String
firstToUpper(String s)
static String
fixCapitalization(String string)
Capitalises the first character of the string and all characters that follow periods, exclamation and question marks.static byte[]
static int
indexOfOutsideGroup(String string, char find, char groupOpen, char groupClose, int i)
static String
static String
static String
static String
static String
static String
static String
multiply(char c, int amount)
static String
static double
numberAfter(CharSequence s, int index)
Shorthand fornumberAt
(s, index, true)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.static double
numberBefore(CharSequence s, int index)
Shorthand fornumberAt
(s, index, false)static String
static @Nullable String
replaceAll(CharSequence string, String regex, Callback<String,Matcher> callback)
Performs regex replacing using a callback.static @Nullable String
replaceAll(CharSequence string, Pattern regex, Callback<String,Matcher> callback)
Performs regex replacing using a callback.static String
replaceFirst(String haystack, String needle, String replacement, boolean caseSensitive)
static boolean
startsWithIgnoreCase(String string, String start)
static boolean
startsWithIgnoreCase(String string, String start, int offset)
static String
Equal toString.substring(int, int)
, but allows negative indices that are counted from the end of the string.static String
toString(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)
-