Package net.sf.json.util
Class JavaIdentifierTransformer
java.lang.Object
net.sf.json.util.JavaIdentifierTransformer
Transforms a string into a valid Java identifier.
There are five predefined strategies:
There are five predefined strategies:
- NOOP: does not perform transformation.
- CAMEL_CASE: follows the camel case convention, deletes non JavaIdentifierPart chars (including whitespace).
- UNDERSCORE: replaces sequences of non JavaIdentifierPart chars (including whitespace) with single '_' separators.
- WHITESPACE: deletes non JavaIdentifierPart chars (including whitespace).
- STRICT: always throws a JSONException, does not perform transformation.
- Author:
- Andres Almiray aalmiray@users.sourceforge.net
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JavaIdentifierTransformerCamelCase transformer 'camel case' =gt; 'camelCase'static final JavaIdentifierTransformerNoop transformer '@invalid' => '@invalid'static final JavaIdentifierTransformerStrict transformer '@invalid' => JSONExceptionstatic final JavaIdentifierTransformerUnderscore transformer 'under score' => 'under_score'static final JavaIdentifierTransformerWhitespace transformer 'white space' => 'whitespace' -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
CAMEL_CASE
CamelCase transformer 'camel case' =gt; 'camelCase' -
NOOP
Noop transformer '@invalid' => '@invalid' -
STRICT
Strict transformer '@invalid' => JSONException -
UNDERSCORE
Underscore transformer 'under score' => 'under_score' -
WHITESPACE
Whitespace transformer 'white space' => 'whitespace'
-
-
Constructor Details
-
JavaIdentifierTransformer
public JavaIdentifierTransformer()
-
-
Method Details
-
transformToJavaIdentifier
-
shaveOffNonJavaIdentifierStartChars
Removes all non JavaIdentifier chars from the start of the string.- Throws:
JSONException- if the resulting string has zero length.
-