Class Strings.Splitter

java.lang.Object
app.babylon.text.Strings.Splitter
Enclosing class:
Strings

public static final class Strings.Splitter extends Object
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('|');
 String[] fields = PIPE_SPLITTER.withRemoveEmpty(false).split(source);
 
  • Method Details

    • withSplitter

      public Strings.Splitter withSplitter(char splitter)
      Returns a splitter with the delimiter character used to split input. The default delimiter is comma.
    • withStripping

      public Strings.Splitter withStripping(boolean strip)
      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 is true.

    • withRemoveEmpty

      public Strings.Splitter withRemoveEmpty(boolean removeEmpty)
      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 is true.

    • split

      public String[] split(CharSequence source)
      Splits the whole source using this splitter configuration.
    • split

      public String[] split(CharSequence source, int start, int length)
      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.