Class StringSplitter.Shell

java.lang.Object
dev.sympho.modular_commands.utils.StringSplitter.Shell
All Implemented Interfaces:
StringSplitter, StringSplitter.Async, Function<String,List<String>>
Enclosing interface:
StringSplitter

public static class StringSplitter.Shell extends Object implements StringSplitter.Async
A splitter that uses a shell-like splitting algorithm, where components are separated by spaces, with the option of one or more components being delimited by quotes (single or double) to allow for the inclusion of spaces.

Leading and trailing whitespace is ignored.

Since:
1.0
Version:
1.0
  • Constructor Details

    • Shell

      public Shell()
      Creates a new instance.
  • Method Details

    • delimiter

      public String delimiter()
      Description copied from interface: StringSplitter
      Obtains a string that can be used to delimit two elements according to this splitter.

      Note that there is no guarantee that the value returned by this method is the only delimiter supported by this splitter, only that it is a valid delimiter.

      In other words, the guarantee offered by this method is that, given some string str and splitter spl, and l = spl.split(str), then spl.split(String.join(spl.delimiter(), l)).equals(l) is true.

      This implies that, for any sequence of strings s1, s2, s3, ..., then spl.split(String.join(spl.delimiter(), s1, s2, s3, ...)) gives the same result as concatenating spl.split(s1), spl.split(s2), spl.split(s3), ...

      Specified by:
      delimiter in interface StringSplitter
      Returns:
      The delimiter.
    • takeNext

      public String takeNext(String state, Consumer<String> sink)
      Description copied from interface: StringSplitter.Async
      Takes the next element from the current state.
      Specified by:
      takeNext in interface StringSplitter.Async
      Parameters:
      state - The current processing state.
      sink - The sink to send the next element into.
      Returns:
      The new state.