public static class StringEscapes.JavaStringEscapes
extends java.lang.Object
Constructor and Description |
---|
JavaStringEscapes() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
escapeJavaString(java.lang.String value)
converts normal string to java escaped for double-quotes (but not wrapped in double quotes)
|
static void |
escapeJavaString(java.lang.String value,
java.lang.Appendable out)
converts normal string to java escaped for double-quotes (but not wrapped in double quotes)
|
static Maybe<java.util.List<java.lang.Object>> |
tryUnwrapJsonishList(java.lang.String input)
converts a comma separated list in a single string to a list of json primitives or maps,
falling back to returning the input.
|
static java.lang.String |
unwrapJavaString(java.lang.String s)
given a string in java syntax, e.g.
|
static java.lang.String |
unwrapJavaStringIfWrapped(java.lang.String s)
as
unwrapJavaString(String) if the given string is wrapped in double quotes;
otherwise just returns the given string |
static java.util.List<java.lang.String> |
unwrapJsonishListIfPossible(java.lang.String input)
Deprecated.
since 1.0.0, use
unwrapJsonishListStringIfPossible(String) (old semantics)
or tryUnwrapJsonishList(String) (improved) |
static java.util.List<java.lang.String> |
unwrapJsonishListStringIfPossible(java.lang.String input)
converts a comma separated list in a single string to a list of strings,
doing what would be expected if given java or json style string as input,
and falling back to returning the input.
|
static java.util.List<java.lang.String> |
unwrapOptionallyQuotedJavaStringList(java.lang.String input)
as
unwrapJsonishListIfPossible(String) but throwing errors
if something which looks like a string or set of brackets is not well-formed
(this does the work for that method) |
static java.util.List<java.lang.String> |
unwrapQuotedJavaStringList(java.lang.String s,
java.lang.String separator)
Unwraps a sequence of quoted java strings, that are each separated by the given separator.
|
static java.lang.String |
wrapJavaString(java.lang.String value)
converts normal string to java escaped for double-quotes and wrapped in those double quotes
|
static void |
wrapJavaString(java.lang.String value,
java.lang.Appendable out)
converts normal string to java escaped for double-quotes and wrapped in those double quotes
|
static java.util.List<java.lang.String> |
wrapJavaStrings(java.lang.Iterable<java.lang.String> values) |
public static java.lang.String escapeJavaString(java.lang.String value)
public static java.lang.String wrapJavaString(java.lang.String value)
public static java.util.List<java.lang.String> wrapJavaStrings(java.lang.Iterable<java.lang.String> values)
public static java.lang.String unwrapJavaStringIfWrapped(java.lang.String s)
unwrapJavaString(String)
if the given string is wrapped in double quotes;
otherwise just returns the given stringpublic static void wrapJavaString(java.lang.String value, java.lang.Appendable out) throws java.io.IOException
java.io.IOException
public static void escapeJavaString(@Nonnull java.lang.String value, java.lang.Appendable out) throws java.io.IOException
java.io.IOException
public static java.lang.String unwrapJavaString(java.lang.String s)
public static java.util.List<java.lang.String> unwrapQuotedJavaStringList(java.lang.String s, java.lang.String separator)
trimmedArg
- public static java.util.List<java.lang.String> unwrapJsonishListIfPossible(java.lang.String input)
unwrapJsonishListStringIfPossible(String)
(old semantics)
or tryUnwrapJsonishList(String)
(improved)public static Maybe<java.util.List<java.lang.Object>> tryUnwrapJsonishList(java.lang.String input)
specifically:
[ X ]
(in brackets after trim), parse as YAML;
if parse succeeds return the result, or if parse fails, return Maybe.absent()
.
[ X ]
, wrap in brackets and parse as YAML,
and if that succeeds and is a list, return the result.
",.
and not starting with '
, and returns the list of those tokens, where A is
returned as its string value, and B as a primitive if it is a number or boolean or null,
or else a string (including the empty string if empty)
Maybe.absent()
.
public static java.util.List<java.lang.String> unwrapJsonishListStringIfPossible(java.lang.String input)
this method does not throw exceptions on invalid input, but just returns that input wrapped in a list
specifically, uses the following rules (executed once in sequence:
[ X ]
(in brackets after trim),
then removes brackets and applies following rules to X (for any X including quoted or with commas)
"X"
(in double quotes after trim,
where X contains no internal double quotes unless escaped with backslash)
then returns list containing X unescaped (\x replaced by x)
X
or X, Y, ...
(where X, Y, ... each satisfy the constraint given in 2, or have no double quotes or commas in them)
then returns the concatenation of rule 2 applied to non-empty X, Y, ...
(if you want an empty string in a list, you must double quote it)
public static java.util.List<java.lang.String> unwrapOptionallyQuotedJavaStringList(java.lang.String input)
unwrapJsonishListIfPossible(String)
but throwing errors
if something which looks like a string or set of brackets is not well-formed
(this does the work for that method)java.lang.IllegalArgumentException
- if looks to have quoted list or surrounding brackets but they are not syntactically valid