Class ParamsParser

java.lang.Object
io.nosqlbench.nb.api.config.params.ParamsParser

public class ParamsParser
extends java.lang.Object

Synopsis

This is a multi-purpose special parser for parameters in a command or other map. It is called special because it does take a few liberties which are not commonly found in regular languages, but which may be desirable for casual use. This is done in a very specific way such that interpretation is unambiguous.

Basic Format

The input line consists of a sequence of names and values, called assignments. These occur as name=value, and may be delimited by spaces or semicolons, like name1=value1 name2=value2 or name1=value1;name2=value2. Values can even contain spaces, even though space is a possible delimiter. Thus, name1= value foo bar name2=baz works, with the values value foo bar and baz.

Names

The name of a parameter must appear in raw literal form, with no escaping. A name may not contain spaces, semicolons or equals signs, and may not start with quotes of any kind. Otherwise, there are no restrictions placed on the characters that may appear in a name. Even escaped characters are allowed.

Values

Values can appear as single quoted values, double quoted values, or literal values. The way the value is parsed is determined by the leading character, respectively.

Single Quoted

If the leading character is a single quote, then all following characters up to the next single quote are taken as the value, except for escape characters which work as expected. Double quotes, spaces, equals or any other characters have no special meaning within a single quoted value.

Double Quoted

If the leading character is a double quote, then all following characters up to the next double quote are taken as the value, except for escape characters which work as expected. Single quotes, spaces, equals or other characters have no special meaning within double quotes.

Literal

Otherwise, the value is taken as every single character, including spaces, single quotes, and double quotes, up to the end of the command line or the next parameter assignment. Any occurrence of semicolons which is not escaped will be treated as a delimiter. The next occurrence of a name and equals pattern after a space will be taken as the next named parameter. Otherwise, all spaces and partial word are included in the last value assigment found. Leading spaces on literal values are skipped unless escaped.

Detection

When a caller wants to parse this format optionally when the format is recognizable as having parameters, the hasValues(String) method can be called. To be recognized as having parameters, a more strict definition is used: The patter must start with a simple assignment having a varname which starts with an alphabetic character or an underscore, followed by any alpha-numeric, dot ., dash -, or underscore _ with an assignment character = following. The following regex can be used as an example for documentation purposes when explaining op mapping conventions to users:

 [_a-zA-Z][-_.\\w]*
 
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String ASSIGN_CHARS  
  • Constructor Summary

    Constructors 
    Constructor Description
    ParamsParser()  
  • Method Summary

    Modifier and Type Method Description
    static boolean hasValues​(java.lang.String input)  
    static boolean hasValues​(java.lang.String input, java.lang.String assignChars)  
    static java.util.Map<java.lang.String,​java.lang.String> parse​(java.lang.String input, boolean canonicalize)  
    static java.util.Map<java.lang.String,​java.lang.String> parse​(java.lang.String input, java.lang.String assignmentCharacters, boolean canonicalize)
    Parse a string input as a loose-form param=value list, and be reasonable about formatting conventions that most users would follow in the absence of detailed rules.
    static java.util.Map<java.lang.String,​java.lang.String> parseToMap​(java.lang.Object src, java.lang.String mainField)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • parse

      public static java.util.Map<java.lang.String,​java.lang.String> parse​(java.lang.String input, boolean canonicalize)
    • hasValues

      public static boolean hasValues​(java.lang.String input)
    • hasValues

      public static boolean hasValues​(java.lang.String input, java.lang.String assignChars)
    • parse

      public static java.util.Map<java.lang.String,​java.lang.String> parse​(java.lang.String input, java.lang.String assignmentCharacters, boolean canonicalize)
      Parse a string input as a loose-form param=value list, and be reasonable about formatting conventions that most users would follow in the absence of detailed rules. See ParamsParser for more details on how this works.
      Parameters:
      input - The string form containing the parameter names and values to be extracted.
      canonicalize - Whether or not to replace synonyms with modern forms and to warn when old forms are used
      Returns:
      A map of extracted keys and values
    • parseToMap

      public static java.util.Map<java.lang.String,​java.lang.String> parseToMap​(java.lang.Object src, java.lang.String mainField)