java.lang.Object | |
↳ | com.pnfsoftware.jeb.util.format.Strings |
Utility methods for Strings and CharSequences.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
public static final String | LINESEP | Line-separator for *this* platform. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Strings() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static String |
camelCaseToString(String s, boolean breakOnDigits, boolean keepUppercaseAcronyms)
Convert a camel-case string to a sentence.
| ||||||||||
static String |
camelCaseToString(String s)
Convert a camel-case string to a sentence.
| ||||||||||
static String |
capitalizeFirst(String s)
Capitalize the first character of a string.
| ||||||||||
static boolean |
contains(String s, String... elts)
A many-element variant of
String.contains . | ||||||||||
static boolean |
containsAt(String s, int index, String elt)
Indicates if a String s contains a particular substring at a specified index.
| ||||||||||
static int |
count(String str, String sub, boolean countOverlaps)
Count the number of occurrences of a sub-string within a string.
| ||||||||||
static int |
count(String str, char ch)
Count the number of occurrences of a character within a string.
| ||||||||||
static int |
countNonBlankCharacters(CharSequence s)
Count the number of non blank characters in the provided string.
| ||||||||||
static String |
decodeASCII(byte[] bytes)
Decode a byte buffer using an ASCII decoder.
| ||||||||||
static String |
decodeASCII(byte[] bytes, int offset, int length)
Decode a byte buffer using an ASCII decoder.
| ||||||||||
static String[] |
decodeArray(String s)
Decode an encoded array of objects.
| ||||||||||
static List<String> |
decodeList(String s)
Decode an encoded list of objects.
| ||||||||||
static String |
decodeLocal(byte[] bytes, int offset, int length)
Decode a byte buffer using the local platform's default charset.
| ||||||||||
static String |
decodeLocal(byte[] bytes)
Decode a byte buffer using the local platform's default charset.
| ||||||||||
static Map<String, String> |
decodeMap(String s)
Decode an encoded map.
| ||||||||||
static String |
decodeUTF8(byte[] bytes)
Decode a byte buffer using a UTF-8 decoder.
| ||||||||||
static String |
decodeUTF8(byte[] bytes, int offset, int length)
Decode a byte buffer using a UTF-8 decoder.
| ||||||||||
static String | decodeUTF8Ex(byte[] bytes, int off, int len, boolean useStandardDecoderFirst) | ||||||||||
static String | decodeUTF8Ex(byte[] bytes, boolean useStandardDecoderFirst) | ||||||||||
static Charset |
determinePotentialEncoding(byte[] data, int offset, int size)
Heuristically determine the encoding of a string.
| ||||||||||
static byte[] |
encodeASCII(String s)
Encode a string using an ASCII encoder.
| ||||||||||
static String |
encodeArray(Object... array)
Encode an array of objects.
| ||||||||||
static byte[] |
encodeBinary(String s)
Generate a byte array consisting of the low-bytes of the input string characters.
| ||||||||||
static String |
encodeList(List<?> list)
Encode a list of objects.
| ||||||||||
static byte[] |
encodeLocal(String s)
Encode a string using the local platform's default charset.
| ||||||||||
static String |
encodeMap(Map<?, ?> map)
Encode a dictionary.
| ||||||||||
static byte[] |
encodeUTF8(String s)
Encode a string using a UTF-8 encoder.
| ||||||||||
static boolean |
endsWith(String s, String... elts)
A many-element variant of
String.endsWith . | ||||||||||
static boolean |
equals(String a, String b)
A safer version of
equals(Object) . | ||||||||||
static boolean |
equalsIgnoreCase(String a, String b)
A safer version of
equalsIgnoreCase(String) | ||||||||||
static String |
f(String format, Object... args)
Format using the US locale.
| ||||||||||
static Appendable |
ff(Appendable sink, String format, Object... args)
A faster version of String#format(String, Object...).
| ||||||||||
static Appendable |
ff(Locale l, Appendable sink, String format, Object... args)
A faster version of String#format(String, Object...).
| ||||||||||
static String |
ff(Locale l, String format, Object... args)
A faster version of String#format(String, Object...).
| ||||||||||
static String |
ff(String format, Object... args)
A faster version of String#format(String, Object...).
| ||||||||||
static int[] |
findWordBoundaries(String str, int offset)
Find a word in the string
| ||||||||||
static int[] |
findWordBoundaries(String str, int offset, Predicate<Character> boundaryTester)
Find a word in the string
| ||||||||||
static String | firstLine(String s) | ||||||||||
static String |
generate(CharSequence s, int count)
Generate a repeated string.
| ||||||||||
static String |
generate(char c, int count)
Generate a repeated-character String.
| ||||||||||
static int |
getAsciiLength(byte[] data)
Same as
getAsciiLength(data, data.length) . | ||||||||||
static int |
getAsciiLength(byte[] data, int maxlen)
Retrieve the length of a potentially ASCII-encoded string.
| ||||||||||
static int |
getBOMSize(byte[] input)
Retrieve the size taken by the BOM or equivalent encoding mark.
| ||||||||||
static Comparator<String> |
getComparator()
Get a case-sensitive string comparator that treats hexadecimal sequences as numbers, and
orders them accordingly, instead as simple strings.
| ||||||||||
static Comparator<String> |
getComparator(boolean caseSensitive, boolean scanHexadecimal)
Get a string comparator that can treat hexadecimal sequences as numbers (and order them
accordingly) instead as simple strings.
| ||||||||||
static int | getFastFormatFailureCount() | ||||||||||
static int | getFastFormatInvocationCount() | ||||||||||
static int |
getInitialBlankSize(InputStream stream, boolean includeBOM, char... extraWhitespaceCharacters)
Retrieve the initial blank bytes at the beginning of a stream (non data)
| ||||||||||
static boolean |
hasBlank(CharSequence s)
Determine if a string contains one or more WSP characters.
| ||||||||||
static boolean |
hasLength(CharSequence s)
Determine if a string is non-null and non-empty.
| ||||||||||
static boolean |
hasRtl(CharSequence s)
Determine if a string contains right-to-left (RTL) characters, eg Arabic or Hebrew
characters.
| ||||||||||
static String |
indentBlock(String blk)
Indent a buffer using a 4-space indentation.
| ||||||||||
static String |
indentBlock(String blk, String indent)
Indent a buffer.
| ||||||||||
static int |
indexOf(CharSequence text, char c)
Implementation of
indexOf for CharSequence. | ||||||||||
static int |
indexOf2(CharSequence text, int from, char c0, char c1)
Find the first one of two characters and return its position.
| ||||||||||
static int |
indexOf2(CharSequence text, char c0, char c1)
Find the first one of two characters and return its position.
| ||||||||||
static int |
indexOfAny(CharSequence text, Set<Character> cset)
Find the first one of any of the provided characters and return its position.
| ||||||||||
static int |
indexOfNotInGroup(CharSequence text, char c, int fromIndex, char... ingoreInGroups)
Find the index a of character, ignoring some groups.
| ||||||||||
static boolean |
isAsciiWhitespace(int b, char... extraWhitespaceCharacters)
Determine if a character is a white-space, per the Ascii standard.
| ||||||||||
static boolean |
isBlank(CharSequence s)
Determine if a character sequence is null, empty, or contains WSP chars exclusively.
| ||||||||||
static boolean |
isContainedIn(String s, String... elts)
Determine if a string is contained in an var-arg list of provided strings.
| ||||||||||
static boolean | isNumber(String text) | ||||||||||
static boolean |
isPrintableCharsetHeader(byte[] headerBytes, Charset charset)
Validate if some starting bytes may be encoded with a particular charset.
| ||||||||||
static boolean |
isPrintableUTF8Header(byte[] headerBytes)
Validate if some starting bytes may be considered as an UTF-8 printable character header.
| ||||||||||
static boolean | isWellFormedUTF8(byte[] bytes) | ||||||||||
static boolean | isWellFormedUTF8(byte[] bytes, int off, int len) | ||||||||||
static boolean |
isWhitespace(char c)
Determine if a character is a white-space, per the Unicode standard.
| ||||||||||
static <T> String |
join(String separator, Iterable<T> iterator, Function<T, CharSequence> f)
Join a series of items.
| ||||||||||
static String |
join(String separator, Iterable<?> iterator)
Join the string representations of a sequence of objects using the provided separator.
| ||||||||||
static String |
join(String separator, String[] elts, int begin, int end)
Join a series of non-null strings.
| ||||||||||
static String |
join(String separator, Object... objects)
Join the string representations of a sequence of objects using the provided separator.
| ||||||||||
static String |
joinList(Iterable<?> objects)
Join the elements of a list using "," as a separator and surround the resulting string with
square brackets.
| ||||||||||
static String |
joinv(String separator, String defaultValue, Object... objects)
Join the string representations of a sequence of objects using the provided separator.
| ||||||||||
static String |
joinv(String separator, Object... objects)
Join the string representations of a sequence of objects using the provided separator.
| ||||||||||
static int |
lastIndexOf2(CharSequence text, int from, char c0, char c1)
Find the last one of two characters and return its position.
| ||||||||||
static int |
lastIndexOf2(CharSequence text, char c0, char c1)
Find the last one of two characters and return its position.
| ||||||||||
static int |
lastIndexOfAny(CharSequence text, Set<Character> cset)
Find the last one of any of the provided characters and return its position.
| ||||||||||
static boolean |
like(String str, String pat)
Check whether an input string matches a provided Pattern regex pattern.
| ||||||||||
static boolean |
likei(String str, String pat)
Check whether an input string matches a provided Pattern regex pattern.
| ||||||||||
static String |
ltrim(String s, char c)
Left trim on a given character.
| ||||||||||
static String |
ltrim(String s)
Left trim all chars less than or equal to ' '.
| ||||||||||
static void |
makeNewLine(StringBuilder sb)
Append a new-line character to the provided buffer unless the buffer is empty or the last
character in the buffer is a new-line.
| ||||||||||
static String |
normalizeNewLines(String s)
Replace all newline sequences by the standard \n LF charcter.
| ||||||||||
static CharSequence |
pad(char c, int count)
Repeat character c, iter times and build a CharSequence from it.
| ||||||||||
static String[] |
parseCommandline(String s)
Parse a string as a command line.
| ||||||||||
static String |
parseUrlParameter(String s, String entry)
Same as
parseUrlParameters(String, String...) with a single entry. | ||||||||||
static String[] |
parseUrlParameters(String s, String... entries)
Extract the parameters of a URL-like encoded string.
| ||||||||||
static String |
randomUniqueId()
Generate a 32-character long random unique identifier.
| ||||||||||
static String |
readBOM(byte[] input)
Retrieve the charset from start bytes.
| ||||||||||
static String |
replaceLast(String str, String target, String replacement)
Replace the last occurrence of target in str by the replacement
| ||||||||||
static String |
replaceNewLines(String s, String repl)
Replace newline sequences.
| ||||||||||
static String |
replaceWhitespaces(String str, char repl)
Efficiently replace all Unicode white-spaces by the provided char.
| ||||||||||
static void | resetFastFormatCounts() | ||||||||||
static String |
rtrim(String s, char c)
Right trim on a given character.
| ||||||||||
static String |
rtrim(String s)
Right trim all chars less than or equal to ' '.
| ||||||||||
static String |
safe(Object s)
Get the string representation of the parameter object, or the empty string if the object is
null.
| ||||||||||
static String |
safe(Object s, String def)
Get the string representation of the parameter object, or the provided string if the object
is null.
| ||||||||||
static String |
safe2(Object s, String def)
Get the string representation of the parameter object, or the provided non-empty string if
the object is null or its string representation is the empty string.
| ||||||||||
static int |
search(CharSequence data, int index, String pattern, boolean regex, boolean caseSensitive, boolean reverseSearch)
Search for a sub-string.
| ||||||||||
static String |
spaces(int count)
Generate a repeated string of spaces.
| ||||||||||
static String[] |
splitLines(String s, boolean doNotReturnFinalEmptyLine)
Split a text into an array of Lines.
| ||||||||||
static String[] |
splitLines(String s)
Split a text into an array of Lines.
| ||||||||||
static String[] | splitall(String s, String delim) | ||||||||||
static boolean |
starMatches(String str, String pat)
Check whether an input string matches a provided pattern using a
StarMatcher . | ||||||||||
static boolean |
startsWith(String s, String... elts)
A many-element variant of
String.startsWith . | ||||||||||
static String |
substring(String s, int begin, int end)
Flexible version of
substring(int, int) . | ||||||||||
static String |
toString(Object o)
A safe version of
String.toString . | ||||||||||
static String |
toString(Object o, String defaultValue)
A safe version of
String.toString . | ||||||||||
static String |
trim(String s)
Trim (left and right) all chars less than or equal to ' '.
| ||||||||||
static String |
trim(String s, char c)
Trim (left and right) all chars to provided character.
| ||||||||||
static String |
trimWhitespaces(String s)
Trim (left and right) all characters considered to be white-space by the Unicode standard.
| ||||||||||
static String |
truncate(String s, int maxLength)
Truncate a string.
| ||||||||||
static String |
truncateWithSuffix(String s, int maxLength, String suffix)
Truncate a string and append an optional suffix to it if it was actually truncated.
| ||||||||||
static String |
urldecodeUTF8(String s)
Decode a
URL-encoded string. | ||||||||||
static String |
urlencodeUTF8(String s)
Urlencode a string.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Line-separator for *this* platform.
Convert a camel-case string to a sentence. Example:
ThisIsACamelCaseString -> This is a camel case string ThisIsACamel44CaseString -> This is a camel44 case string CountryUSA -> Country u s a with breakOnDigits=true: ThisIsACamel44CaseString -> This is a camel 44 case string with keepUppercaseAcronyms=true: CountryUSA -> Country USAA legal camel-case string always starts with an upper-case letter, and does not contain whitespace characters.
s | the input camel-case string |
---|---|
breakOnDigits | if true, base-10 numbers will also be used as breaks |
keepUppercaseAcronyms | keep 2+ upper-case letter acronyms intact, eg:
CountryUSA would be converted to Country USA instead of
Country u s a |
ParseException | if the input string was not camel-case formatted |
---|
Convert a camel-case string to a sentence. Example:
ThisIsACamelCaseString -> This is a camel case stringA legal camel-case string always starts with an upper-case letter, and does not contain whitespace characters.
s | the input camel-case string |
---|
ParseException | if the input string was not camel-case formatted |
---|
Capitalize the first character of a string.
A many-element variant of String.contains
.
s | the string |
---|---|
elts | a list of string elements |
Indicates if a String s contains a particular substring at a specified index. Semantically
equivalent to s.substring(i).startsWith(elt)
without intermediate substring
creation.
s | the string |
---|---|
index | String index to look at |
elt | element to identify |
Count the number of occurrences of a sub-string within a string.
Note: a search for 'aaa' inside 'aaaaaa' would return 4, not 2!
str | haystack |
---|---|
sub | needle |
countOverlaps | if true, a search for 'aaa' inside 'aaaaaa' will return 4 instead of 2 |
Count the number of occurrences of a character within a string.
str | haystack |
---|---|
ch | needle |
Count the number of non blank characters in the provided string.
Decode a byte buffer using an ASCII decoder. If the decoder is not available, the byte buffer is decoded using the system's default decoder.
bytes | mandatory byte buffer |
---|
Decode a byte buffer using an ASCII decoder. If the decoder is not available, the byte buffer is decoded using the system's default decoder.
bytes | byte buffer |
---|---|
offset | start offset |
length | count of bytes to be decoded |
Decode an encoded array of objects.
s | the encoded array |
---|
Decode an encoded list of objects.
s | optional encoded list |
---|
Decode a byte buffer using the local platform's default charset. This method is potentially dangerous.
bytes | byte buffer |
---|---|
offset | start offset |
length | count of bytes to be decoded |
Decode a byte buffer using the local platform's default charset. This method is potentially dangerous.
bytes | mandatory byte buffer |
---|
Decode an encoded map.
s | optional encoded map |
---|
Decode a byte buffer using a UTF-8 decoder. If the decoder is not available, the byte buffer is decoded using the system's default decoder.
bytes | mandatory byte buffer |
---|
Decode a byte buffer using a UTF-8 decoder. If the decoder is not available, the byte buffer is decoded using the system's default decoder.
bytes | byte buffer |
---|---|
offset | start offset |
length | count of bytes to be decoded |
Heuristically determine the encoding of a string.
Encode a string using an ASCII encoder. If the encoder is not available, the string is encoded using the system's default encoder. This should never happen.
s | mandatory string |
---|
Encode an array of objects.
array | the array of objects |
---|
Generate a byte array consisting of the low-bytes of the input string characters.
Encode a list of objects.
list | the list of objects |
---|
Encode a string using the local platform's default charset. This method is potentially dangerous.
s | mandatory string |
---|
Encode a dictionary. The encoding scheme will produce strings like:
encodedKey1=encodedValue1&encodedKey2=encodedValue2&...
map | the map of key/values |
---|
Encode a string using a UTF-8 encoder. If the encoder is not available, the string is encoded using the system's default encoder. This should never happen.
s | mandatory string |
---|
A many-element variant of String.endsWith
.
s | the string |
---|---|
elts | a list of string elements |
A safer version of equals(Object)
.
a | first string, may be null |
---|---|
b | second string, may be null |
A safer version of equalsIgnoreCase(String)
a | first string, may be null |
---|---|
b | second string, may be null |
Format using the US locale.
A faster version of String#format(String, Object...).
sink | optional recipient (if null, a new builder will be created; the formatted string is appended to the sink) |
---|---|
format | format string |
args | format arguments |
A faster version of String#format(String, Object...).
l | locale to be used |
---|---|
sink | optional recipient (if null, a new builder will be created; the formatted string is appended to the sink) |
format | format string |
args | format arguments |
A faster version of String#format(String, Object...).
l | locale to be used |
---|---|
format | format string |
args | format arguments |
A faster version of String#format(String, Object...).
format | format string |
---|---|
args | format arguments |
Find a word in the string
str | a string |
---|---|
offset | offset in the string, for which the underlying word should be found |
Find a word in the string
str | a string |
---|---|
offset | offset in the string, for which the underlying word should be found |
Generate a repeated string.
s | string to repeat |
---|---|
count | repeat count |
Generate a repeated-character String. For CharSequence generation, use
pad(char, int)
.
c | character to repeat |
---|---|
count | repeat count (ie, string length) |
Same as getAsciiLength(data, data.length)
.
data | a bybte array |
---|
Retrieve the length of a potentially ASCII-encoded string. The String characters allowed are contained CR, LF, TAB, and any character in the [0x20, 0x7E] range.
data | a byte array |
---|---|
maxlen | maximum length |
Retrieve the size taken by the BOM or equivalent encoding mark. Detect UTF-8, UTF-16 and UTF-32.
input | byte array. Be sure to have at least 4 bytes to analyze all. |
---|
Get a case-sensitive string comparator that treats hexadecimal sequences as numbers, and orders them accordingly, instead as simple strings.
Refer to NumberComparator
and AlphanumCharComparator
for details.
Get a string comparator that can treat hexadecimal sequences as numbers (and order them accordingly) instead as simple strings.
Refer to NumberComparator
and AlphanumCharComparator
for details.
Retrieve the initial blank bytes at the beginning of a stream (non data)
stream | input Stream to analyze |
---|---|
includeBOM | true will consider BOM at start of the stream as an initial blank bytes |
IOException |
---|
Determine if a string contains one or more WSP characters.
Determine if a string is non-null and non-empty.
Determine if a string contains right-to-left (RTL) characters, eg Arabic or Hebrew characters.
Indent a buffer using a 4-space indentation.
Indent a buffer.
Implementation of indexOf
for CharSequence. Same behavior as
indexOf(int)
.
text | string |
---|---|
c | char |
Find the first one of two characters and return its position.
text | string |
---|---|
from | start index |
c0 | first char |
c1 | second char |
Find the first one of two characters and return its position.
This is a 2-element implementation of indexOf(int)
.
text | string |
---|---|
c0 | first char |
c1 | second char |
Find the first one of any of the provided characters and return its position.
This is a N-element implementation of indexOf(int)
.
cset | a set of characters |
---|
Find the index a of character, ignoring some groups.
For example:
indexOfNotInGroup("it is (almost) done", 'o', 0, ['(',
')'])
will return 16indexOfNotInGroup("std::myclass::mymethod(type a, type b)", ',', 0, ['<',
'>'])
will return 34text | string |
---|---|
c | character to find |
fromIndex | start index, use 0 by default |
ingoreInGroups | list of character groups to be ignored {'(', ')'}, {'<', '>'}. Each character group must contain at least 2 elements (one for open element, one for close element) |
Determine if a character is a white-space, per the Ascii standard. It only processes regular space, tab, CR and LF characters.
b | the int to test |
---|---|
extraWhitespaceCharacters | additional ascii characters considered as whitespace |
Determine if a character sequence is null, empty, or contains WSP chars exclusively.
s | the character sequence |
---|
Determine if a string is contained in an var-arg list of provided strings.
s | string to be searched |
---|---|
elts | the list of elements |
Validate if some starting bytes may be encoded with a particular charset.
headerBytes | starting bytes. May be cropped without incidence (will be more accurate with more bytes, though). |
---|---|
charset | Charset to detect. USe isPrintableUTF8Header(byte[]) for UTF-8. |
Validate if some starting bytes may be considered as an UTF-8 printable character header.
headerBytes | starting bytes. May be cropped without incidence (will be more accurate with more bytes, though). |
---|
Determine if a character is a white-space, per the Unicode standard. This method differs from
isWhitespace(char)
(Java language definition of a WSP).
Join a series of items. Format items using the function. For example, to display a list of
long as hexadecimal separated by comma:
Strings.join(", ", Arrays.asList(0x10L, 0x20L), l -> Long.toHexString(l))
separator | a non-null separator |
---|---|
f | toString() equivalent method to be applied to objects from list. |
Join the string representations of a sequence of objects using the provided separator. Null objects will be formatted as "null".
separator | a non-null separator |
---|---|
iterator | an iterator |
Join a series of non-null strings.
begin | inclusive start index |
---|---|
end | exclusive end index |
Join the string representations of a sequence of objects using the provided separator. Null objects will be formatted as "null".
This method is error-prone and was deprecated. Use #joinv(String, Object...) joinv instead.
separator | a non-null separator |
---|---|
objects | a sequence of objects |
Join the elements of a list using "," as a separator and surround the resulting string with
square brackets. Careful, this method does not abide to the common semantic of
join
.
objects | a list of objects |
---|
Join the string representations of a sequence of objects using the provided separator.
separator | a non-null separator |
---|---|
defaultValue | String representation for null Objects |
objects | an array of objects |
Join the string representations of a sequence of objects using the provided separator. Null objects will be formatted as "null".
separator | a non-null separator |
---|---|
objects | an array of objects |
Find the last one of two characters and return its position.
text | string |
---|---|
from | start index |
c0 | first char |
c1 | second char |
Find the last one of two characters and return its position.
This is a 2-element implementation of lastIndexOf(int)
.
text | string |
---|---|
c0 | first char |
c1 | second char |
Find the last one of any of the provided characters and return its position.
This is a N-element implementation of lastIndexOf(int)
.
cset | a set of characters |
---|
Check whether an input string matches a provided Pattern regex pattern. This method is case-sensitive.
str | a string |
---|---|
pat | a regular expression |
Check whether an input string matches a provided Pattern regex pattern. This method is case-insensitive.
str | a string |
---|---|
pat | a regular expression |
Left trim on a given character.
Left trim all chars less than or equal to ' '. Note that this method differs from
trim()
which, for instance, does not consider CR or LF to be WSP.
s | a string |
---|
Append a new-line character to the provided buffer unless the buffer is empty or the last character in the buffer is a new-line.
sb | a string builder |
---|
Replace all newline sequences by the standard \n LF charcter.
s | a string |
---|
Repeat character c, iter times and build a CharSequence from it. For example pad('0', 4) will return "0000".
c | inner character |
---|---|
count | times to repeat character. |
Parse a string as a command line. Source: ant.jar.
s | the command line to process. |
---|
Same as parseUrlParameters(String, String...)
with a single entry.
s | the URL-like string to be parsed, containing a single key-value pair, eg
hometype=house |
---|
Extract the parameters of a URL-like encoded string. No decoding is taking place. Example:
- s: "type=home&subtype=house&[another_key]=[another_value]" - entries: "type", "subtype" - returns: ["home", "house"]
s | the string to be parsed |
---|---|
entries | the entries, whose count must match the number of key-value pairs |
Generate a 32-character long random unique identifier. The UID returned consists of the digits 0 to 9 and letters a to f (lower-case).
Retrieve the charset from start bytes. Detect UTF-8, UTF-16LE/BE and UTF-32LE-BE.
input | first bytes of a string |
---|
Replace the last occurrence of target in str by the replacement
str | the string to search in |
---|---|
target | the string to search for |
replacement | the replacement part |
Replace newline sequences. This method accepts null strings as input.
s | a string or null; in the latter case, null will be returned |
---|---|
repl | the non-null substitution string, which must not contain new-line characters |
Efficiently replace all Unicode white-spaces by the provided char.
Right trim on a given character.
Right trim all chars less than or equal to ' '. Note that this method differs from
trim()
which, for instance, does not consider CR or LF to be WSP.
s | a string |
---|
Get the string representation of the parameter object, or the empty string if the object is null.
s | an object, possibly null |
---|
toString()
representation, or the empty string
Get the string representation of the parameter object, or the provided string if the object is null.
s | an object, possibly null |
---|---|
def | a non-null string |
Get the string representation of the parameter object, or the provided non-empty string if the object is null or its string representation is the empty string.
s | an object, possibly null |
---|---|
def | a non-null, non-empty string |
Search for a sub-string.
Note: on JDK 11+, this implementation for
regex=false, caseSensitive=false, reverseSearch=false
may be slower than doing
data.toLowerCase().indexOf(pattern.toLowerCase())
.
data | buffer to be searched (aka, the haystack) |
---|---|
index | in the case of a regular (forward) search, the search takes is [index,EOS); in the case of a reverse (backward) search, the search range is [0,index) |
pattern | text that is being searched (aka, the needle) |
regex | if true, the pattern will be treated as a regular expression; if the regex is invalid, it will be treated as a regular string and no error will be reported |
caseSensitive | search is case-sensitive |
reverseSearch | search is done in reverse |
Generate a repeated string of spaces.
Split a text into an array of Lines. Empty lines are returned. The final new-line character(s) are trimmed off. Works for all new lines characters (\r, \n) or sequences of characters (\r\n)
s | mandatory input string |
---|
Split a text into an array of Lines. Empty lines are returned. The final new-line character(s) are trimmed off. Works for all new lines characters (\r, \n) or sequences of characters (\r\n)
s | mandatory input string |
---|
Check whether an input string matches a provided pattern using a StarMatcher
.
str | a string |
---|---|
pat | a wildcard pattern |
A many-element variant of String.startsWith
.
s | the string |
---|---|
elts | a list of string elements |
Flexible version of substring(int, int)
. Allow Python-like negative indexes
for convenience.
s | a string |
---|---|
begin | index in the [-s_length, +s_length] range |
end | index in the [-s_length, +s_length] range |
A safe version of String.toString
.
o | an object, could be null |
---|
A safe version of String.toString
.
o | an object, could be null |
---|---|
defaultValue | default String representation if o is null |
Trim (left and right) all chars less than or equal to ' '. Note that this method differs from
trim()
which, for instance, does not consider CR or LF to be WSP.
s | a string |
---|
Trim (left and right) all chars to provided character.
s | a string |
---|---|
c | the character to be removed |
Trim (left and right) all characters considered to be white-space by the Unicode standard.
s | the input string |
---|
Truncate a string.
s | a string |
---|---|
maxLength | positive length |
Truncate a string and append an optional suffix to it if it was actually truncated.
s | a string |
---|---|
maxLength | positive length, which must be greater than or equal to the suffix, if one was provided |
suffix | optional suffix appended to a string that is actualy truncated |
Urlencode a string. The resulting string will have the following characteristics:
s | the string to be encoded |
---|