Class JavaIdentifierTransformer

java.lang.Object
net.sf.json.util.JavaIdentifierTransformer

public abstract class JavaIdentifierTransformer extends Object
Transforms a string into a valid Java identifier.
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 Details

  • Constructor Details

    • JavaIdentifierTransformer

      public JavaIdentifierTransformer()
  • Method Details

    • transformToJavaIdentifier

      public abstract String transformToJavaIdentifier(String str)
    • shaveOffNonJavaIdentifierStartChars

      protected final String shaveOffNonJavaIdentifierStartChars(String str)
      Removes all non JavaIdentifier chars from the start of the string.
      Throws:
      JSONException - if the resulting string has zero length.