BUG-582: Operate on characters when checking for leading digit 79/7379/1
authorRobert Varga <rovarga@cisco.com>
Sat, 24 May 2014 06:37:48 +0000 (08:37 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 25 May 2014 10:32:42 +0000 (12:32 +0200)
Do not use strings when we are checking/reconstructing the leading
character -- this allows for more efficient operation.

Change-Id: I4de105ddb9af39e4a28ccc72bc79a15b410ed706
Signed-off-by: Robert Varga <rovarga@cisco.com>
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java

index 17f5b52f4da8ae1dad92bef95bb904abe163c764..cee410c66e050025e749abdff46e6344cb1792dd 100644 (file)
@@ -338,19 +338,14 @@ public final class BindingGeneratorUtil {
         correctStr = replaceWithCamelCase(correctStr, '-');
         correctStr = replaceWithCamelCase(correctStr, '_');
 
-        String firstChar = correctStr.substring(0, 1);
-        if (uppercase) {
-            firstChar = firstChar.toUpperCase();
-        } else {
-            firstChar = firstChar.toLowerCase();
-        }
+        char firstChar = correctStr.charAt(0);
+        firstChar = uppercase ? Character.toUpperCase(firstChar) : Character.toLowerCase(firstChar);
 
-        if (firstChar.matches("[0-9]")) {
-            correctStr = "_" + correctStr;
+        if (firstChar >= '0' && firstChar <= '9') {
+            return correctStr = '_' + correctStr;
         } else {
-            correctStr = firstChar + correctStr.substring(1);
+            return correctStr = firstChar + correctStr.substring(1);
         }
-        return correctStr;
     }
 
     /**