Java Java String Format toJavaConstantIdentifier(String name)

Here you can find the source of toJavaConstantIdentifier(String name)

Description

to Java Constant Identifier

License

Apache License

Declaration

public static String toJavaConstantIdentifier(String name) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String toJavaConstantIdentifier(String name) {
        StringBuilder s = new StringBuilder();
        boolean funnyCharacter = false;
        for (int i = 0; i < name.length(); i++) {
            char ch = name.charAt(i);
            if ((i == 0 && !Character.isJavaIdentifierStart(ch))
                    || (i > 0 && !Character.isJavaIdentifierPart(ch))) {
                funnyCharacter = true;// w  ww .  j  av a 2s.  co m
            } else if (funnyCharacter) {
                s.append("_");
                s.append(Character.toUpperCase(ch));
                funnyCharacter = false;
            } else
                s.append(Character.toUpperCase(ch));
        }
        return s.toString();
    }
}

Related

  1. toJAVA(String unicode)
  2. toJavaBeanPropertyName(String prop)
  3. toJavaBool(byte goBool)
  4. toJavaCasing(final String pName)
  5. toJavaClassName(String str)
  6. toJavadocComment(String comment)
  7. toJavaEnum(String inStr)
  8. toJavaHex(byte in[], int len)
  9. toJavaHexCharString(final char chr)