Package com.apple.foundationdb.util
Class StringUtils
java.lang.Object
com.apple.foundationdb.util.StringUtils
Utility methods for operating with
String
s.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
containsIgnoreCase
(String source, String searchStr) Returns whether some substring ofsource
containssearchStr
, ignoring case.static boolean
Whether the string is a non-empty string containing only numeric characters.static boolean
Whether the substring beginning atbeginIndex
is non-empty and contains only numeric characters.static boolean
Whether the substring frombeginIndex
toendIndex
is non-empty and contains only numeric characters.static String
repeat
(char c, int n) static String
replaceEach
(String source, Map<String, String> replaceMap) Replace all occurrences of the keys of thereplaceMap
in thesource
string with their corresponding value in the map.
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
isNumeric
Whether the string is a non-empty string containing only numeric characters.- Parameters:
s
- string to test for numeric characters- Returns:
- whether
s
contains only numeric characters
-
isNumeric
Whether the substring beginning atbeginIndex
is non-empty and contains only numeric characters. This should be equivalent to callingisNumeric(s.substring(beginIndex))
.- Parameters:
s
- string to test for numeric charactersbeginIndex
- index to begin testing for numeric characters- Returns:
- whether the substring of
s
beginning atbeginIndex
is non-empty and contains only numeric characters
-
isNumeric
Whether the substring frombeginIndex
toendIndex
is non-empty and contains only numeric characters. This should be equivalent to callingisNumeric(s.substring(beginIndex, endIndex))
.- Parameters:
s
- string to test for numeric charactersbeginIndex
- index to begin testing for numeric charactersendIndex
- index to end testing for numeric characters- Returns:
- whether the substring of
s
beginning atbeginIndex
and ending atendIndex
is non-empty and contains only numeric characters
-
repeat
Construct aString
withn
occurrences of a characterc
. Ifn
is less than or equal to zero, the empty string will be returned. Note that if the character is in the high surrogate or low surrogate range (characters necessary to represent Unicode codepoints above U+FFFF in UTF-16), then the returned string will not be valid UTF-16.- Parameters:
c
- a charactern
- the number of times to repeatc
- Returns:
- a string with
n
occurrences of the stringc
- See Also:
-
replaceEach
@Nonnull public static String replaceEach(@Nonnull String source, @Nonnull Map<String, String> replaceMap) Replace all occurrences of the keys of thereplaceMap
in thesource
string with their corresponding value in the map. Elements from thereplaceMap
are processed in order in thesource
string, so if two keys overlap, the one with the lower index will be processed. For example:replaceEach("abc", Map.of("ab", "x", "bc", "y")) = "xc"; replaceEach("abb", Map.of("ab", "x", "bb", "y")) = "xb"; replaceEach("abbb", Map.of("ab", "x", "bb", "y")) = "xy";
If one replacement key is a prefix of another key, then the longer key will be preferred when the longer string is present. (If the other choice was taken, it would never process the longer key, as any time the longer key is found, the shorter key would also be found.) For example:
replaceEach("abc", Map.of("ab", "x", "abc", "y")) = "y"; replaceEach("ababc", Map.of("ab", "x", "abc", "y")) = "xy"; replaceEach("abcab", Map.of("ab", "x", "abc", "y")) = "yx";
- Parameters:
source
- string to perform the find and replace onreplaceMap
- mapping used to transform thesource
string- Returns:
- a string composed by replacing all occurrences of the
replaceMap
keys insource
with their values
-
containsIgnoreCase
Returns whether some substring ofsource
containssearchStr
, ignoring case. This uses the same criteria asString.equalsIgnoreCase(String)
to determine if characters are equal ignoring case.- Parameters:
source
- the source stringsearchStr
- the string to search through- Returns:
- whether some substring of
source
is equal tosearchStr
ignoring case
-