Class Strings
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classConfigurable string splitter. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringclean(CharSequence s, char... removeCharacters) Strips external text withstripx(CharSequence), normalises any remaining whitespace run to a single space, and removes selected characters.static String[]Returns a copy ofvalueswithnullentries removed while preserving order.static String[]Returns a copy ofvalueswith entries matchingremoveomitted while preserving order.static booleanequals(CharSequence s, int start, int end, CharSequence expected) static booleanequalsIgnoreCase(CharSequence s, int start, int end, CharSequence expected) static intindexOf(CharSequence s, char c) static intindexOf(CharSequence s, int start, int end, char c) static intindexOfAny(CharSequence s, char c, char... additional) static intindexOfAny(CharSequence s, int start, int end, char c, char... additional) static booleanisAlpha(char c) static booleanisAlphaNumeric(char c) static booleanstatic booleanisDouble(CharSequence s, int start, int end) static booleanstatic booleanisEmpty(CharSequence s, int start, int end) static booleanstatic booleanisInt(CharSequence s, int start, int end) static booleanstatic booleanisLong(CharSequence s, int start, int end) static booleanReturns true when the supplied sequence is empty after applyingstripx(CharSequence)rules.static booleanisStripxEmpty(CharSequence s, int start, int end) Returns true when the supplied slice is empty after applying the same edge stripping rules asstripx(CharSequence, int, int).static booleanstatic booleanisWholeNumber(CharSequence s, int start, int end) static intlastIndexOf(CharSequence s, char c) static intlastIndexOf(CharSequence s, int start, int end, char c) static intlastIndexOfAny(CharSequence s, char c, char... additional) static intlastIndexOfAny(CharSequence s, int start, int end, char c, char... additional) static CharSequenceleftPad(CharSequence s, int size, char padChar) static CharSequencestatic CharSequenceremoveDiacritics(CharSequence s, int start, int end) static CharSequencerightPad(CharSequence s, int size, char padChar) static String[]Splits comma-separated text using the defaultStrings.Splittersettings.static String[]split(CharSequence s, char splitter) Splits usingsplitter, with the same defaults assplitter():withStripping(true)andwithRemoveEmpty(true).static String[]split(CharSequence s, int start, int end, char splitter) Splits a slice usingsplitter, with the same defaults assplitter():withStripping(true)andwithRemoveEmpty(true).static Strings.Splittersplitter()Creates a reusable splitter configuration.static CharSequenceUnicode-aware edge stripping equivalent toString.strip()forCharSequence.static CharSequencestrip(CharSequence s, int start, int end, CharSequence stripChars) Edge-strips characters from a slice and returns the resulting slice as aCharSequence.static CharSequencestrip(CharSequence s, CharSequence stripChars) Edge-strips characters from the whole source.static intstripEnd(CharSequence s, int start, int end) Returns the exclusive end index of the trimmed slice after Unicode whitespace stripping.static intstripEnd(CharSequence s, int start, int end, CharSequence stripChars) Returns the exclusive end index of the stripped slice after removing any trailing character present instripChars.static intstripStart(CharSequence s, int start, int end) Returns the inclusive start index of the trimmed slice after Unicode whitespace stripping.static intstripStart(CharSequence s, int start, int end, CharSequence stripChars) Returns the inclusive start index of the stripped slice after removing any leading character present instripChars.static CharSequenceUnicode-aware edge stripping for external text.static CharSequencestripx(CharSequence s, int start, int end) static intstripxEnd(CharSequence s, int start, int end) static intstripxStart(CharSequence s, int start, int end) static CharSequencestatic BitSettrace(CharSequence s, char splitter) Finds every occurrence ofsplitterand returns the source indexes as marked bits.static BitSettrace(CharSequence s, int start, int end, char splitter) Finds every occurrence ofsplitterin a slice and returns their indexes as marked bits.static BitSettraceAny(CharSequence s, char splitter, char... additionalSplitters) Finds every occurrence of any supplied splitter and returns the source indexes as marked bits.static BitSettraceAny(CharSequence s, int start, int end, char splitter, char... additionalSplitters) Finds every occurrence of any supplied splitter in a slice and returns their indexes as marked bits.
-
Field Details
-
EMPTY_OR_NULL
-
-
Constructor Details
-
Strings
public Strings()
-
-
Method Details
-
toCamelUpperPreserve
-
leftPad
-
rightPad
-
isAlpha
public static boolean isAlpha(char c) -
isAlphaNumeric
public static boolean isAlphaNumeric(char c) -
equals
-
equalsIgnoreCase
-
isEmpty
-
isEmpty
-
isStripxEmpty
Returns true when the supplied sequence is empty after applyingstripx(CharSequence)rules. -
isStripxEmpty
Returns true when the supplied slice is empty after applying the same edge stripping rules asstripx(CharSequence, int, int). Those rules remove normal Unicode whitespace and the additional ingestion artifacts documented onstripx. -
indexOf
-
indexOf
-
indexOfAny
-
indexOfAny
-
lastIndexOf
-
lastIndexOf
-
lastIndexOfAny
-
lastIndexOfAny
-
trace
Finds every occurrence ofsplitterand returns the source indexes as marked bits.This is intentionally a raw delimiter trace: it does not strip text, remove empty fields, or otherwise apply
Strings.Splitterpolicy. Use it when code needs delimiter positions directly, for example to size arrays or plan low-level parsing. -
trace
Finds every occurrence ofsplitterin a slice and returns their indexes as marked bits.The returned
BitSetis indexed against the original source sequence, not against the supplied slice. For example, a splitter atstartsets bitstart. -
traceAny
Finds every occurrence of any supplied splitter and returns the source indexes as marked bits.This is the multi-delimiter form of
trace(CharSequence, char). The single-character trace overload remains the fast path for the common case and avoids varargs array creation. -
traceAny
public static BitSet traceAny(CharSequence s, int start, int end, char splitter, char... additionalSplitters) Finds every occurrence of any supplied splitter in a slice and returns their indexes as marked bits.The returned
BitSetis indexed against the original source sequence, not against the supplied slice. -
split
Splits usingsplitter, with the same defaults assplitter():withStripping(true)andwithRemoveEmpty(true).This is convenient for one-off calls. For repeated use with the same delimiter, prefer a reusable immutable
Strings.Splitter. -
split
Splits a slice usingsplitter, with the same defaults assplitter():withStripping(true)andwithRemoveEmpty(true).This is convenient for one-off calls. For repeated use with the same delimiter, prefer a reusable immutable
Strings.Splitter. -
split
Splits comma-separated text using the defaultStrings.Splittersettings. -
compact
Returns a copy ofvalueswithnullentries removed while preserving order.If
valuesis already compact, the same array instance is returned. Ifvaluesis null, an empty array is returned. -
compact
Returns a copy ofvalueswith entries matchingremoveomitted while preserving order.If no entries match, the same array instance is returned. If
valuesis null, an empty array is returned. Ifremoveis null, no entries are removed. -
splitter
Creates a reusable splitter configuration.Defaults are comma delimiter,
withStripping(true), andwithRemoveEmpty(true). Stripping uses the same boundary rules asstripx(CharSequence), so it removes Unicode whitespace and common ingestion artifacts such as BOMs, non-breaking spaces, zero-width characters, and replacement characters.Because splitter configurations are immutable, configured instances can be stored as constants for repeated use.
-
isWholeNumber
-
isWholeNumber
-
isInt
-
isInt
-
isLong
-
isLong
-
isDouble
-
isDouble
-
strip
Unicode-aware edge stripping equivalent toString.strip()forCharSequence. -
strip
Edge-strips characters from the whole source.When
stripCharsis null, this uses normal Unicode whitespace rules and behaves likestrip(CharSequence). WhenstripCharsis empty, no characters are stripped. -
strip
Edge-strips characters from a slice and returns the resulting slice as aCharSequence.Slice-oriented parsing code should prefer
stripStart(CharSequence, int, int, CharSequence)andstripEnd(CharSequence, int, int, CharSequence)when it only needs bounds and wants to avoid creating a subsequence view. -
stripStart
Returns the inclusive start index of the trimmed slice after Unicode whitespace stripping.This is intended for slice-oriented parsing code that wants trimmed bounds without first creating a
CharSequence.subSequence(int, int)view. Paired withstripEnd(CharSequence, int, int), callers can decide whether a slice changed and only materialize a subsequence if the downstream parser requires one.Typical usage is to compute stripped start and end bounds, check whether the resulting slice is non-empty, then materialize a subsequence only if needed.
This is generally preferable to a hypothetical
strip(CharSequence, int, int)helper for low-level parsing, because it lets the caller keep control of whether a new view object is created. -
stripStart
Returns the inclusive start index of the stripped slice after removing any leading character present instripChars.When
stripCharsis null, normal Unicode whitespace is stripped. WhenstripCharsis empty,startis returned unchanged. -
stripEnd
Returns the exclusive end index of the trimmed slice after Unicode whitespace stripping.The returned value follows the normal Java
start/endconvention used byCharSequence.subSequence(int, int)andString.substring(int, int):- start is inclusive
- end is exclusive
- See Also:
-
stripEnd
Returns the exclusive end index of the stripped slice after removing any trailing character present instripChars.When
stripCharsis null, normal Unicode whitespace is stripped. WhenstripCharsis empty,endis returned unchanged. -
stripx
Unicode-aware edge stripping for external text. This behaves likeString.strip()for normal whitespace, and also strips common ingestion artifacts that can appear at text boundaries:- non-breaking space (
U+00A0), often copied from HTML, PDFs, and spreadsheets - zero-width space/non-joiner/joiner (
U+200B,U+200C,U+200D), often introduced by copy/paste, web text, PDFs, or rich text editors - byte order mark (
U+FEFF), often found at file or field boundaries - replacement character (
U+FFFD), commonly produced by encoding damage
- non-breaking space (
-
stripx
-
clean
Strips external text withstripx(CharSequence), normalises any remaining whitespace run to a single space, and removes selected characters.Passing
' 'as one of the removable characters removes all normalised whitespace, including tabs and other whitespace characters. This is useful for cleaning human-readable tokens such ashalf-up,half_up, andhalf upto the same key before case conversion.- Parameters:
s- source textremoveCharacters- characters to remove after whitespace normalisation- Returns:
- normalised text or
null
-
removeDiacritics
-
removeDiacritics
-
stripxStart
-
stripxEnd
-