Package app.babylon.text
Class Strings.Splitter
java.lang.Object
app.babylon.text.Strings.Splitter
- Enclosing class:
Strings
Configurable string splitter.
Splitters are immutable. Fluent configuration methods return a new splitter, so configured instances can be safely reused as constants, for example:
static final Strings.Splitter PIPE_SPLITTER = Strings.splitter().withSplitter('|');
static final Strings.Splitter DATE_SPLITTER = Strings.splitter().withSplitters('-', '/');
String[] fields = PIPE_SPLITTER.withRemoveEmpty(false).split(source);
-
Method Summary
Modifier and TypeMethodDescriptionString[]split(CharSequence source) Splits the whole source using this splitter configuration.String[]split(CharSequence source, int start, int end) Splits a slice using this splitter configuration.withRemoveEmpty(boolean removeEmpty) Returns a splitter that controls whether empty fields are omitted from the result.withSplitter(char splitter) Returns a splitter with the delimiter character used to split input.withSplitters(char splitter, char... additionalSplitters) Returns a splitter that treats any of the supplied delimiter characters as a field boundary.withStripping(boolean strip) Returns a splitter that controls whether each field is stripped before it is returned or tested for emptiness.
-
Method Details
-
withSplitter
Returns a splitter with the delimiter character used to split input. The default delimiter is comma. -
withSplitters
Returns a splitter that treats any of the supplied delimiter characters as a field boundary.This is intended for reusable splitter constants. The additional delimiter array is defensively copied so the returned splitter remains immutable.
-
withStripping
Returns a splitter that controls whether each field is stripped before it is returned or tested for emptiness.When enabled, stripping uses
Strings.stripx(CharSequence)rules at field boundaries. The default istrue. -
withRemoveEmpty
Returns a splitter that controls whether empty fields are omitted from the result.When
withStripping(true)is enabled, fields containing only stripx-removable boundary characters are considered empty. The default istrue. -
split
Splits the whole source using this splitter configuration. -
split
Splits a slice using this splitter configuration.The implementation traces delimiter positions once, allocates for the maximum possible number of fields, and only compacts the result if empty fields are removed.
-