axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Dunkin <Dav...@Attachmate.com>
Subject JavaUtils.xmlNameToJava and special characters
Date Thu, 07 Feb 2002 02:10:22 GMT
The xmlNameToJava function munges strings so that they only contain letters
and numbers. However, other characters (such as '$' and '_') are valid in
Java identifiers. Instead of using the Character.isLetter() and
Character.isLetterOrDigit(), why not use Character.isJavaIdentifierStart()
and Character.isJavaIdentifierPart()? Here's a diff:

*** JavaUtils.java      1 Feb 2002 04:38:18 -0000       1.24
--- JavaUtils.java      7 Feb 2002 01:28:24 -0000
***************
*** 315,325 ****
          char[] nameArray = name.toCharArray();
          int nameLen = name.length();
          StringBuffer result = new StringBuffer(nameLen);
          
          // First character, lower case
          int i = 0;
          while (i < nameLen
!                 && !Character.isLetter(nameArray[i])) {
              i++;
          }
          if (i < nameLen) {
--- 315,325 ----
          char[] nameArray = name.toCharArray();
          int nameLen = name.length();
          StringBuffer result = new StringBuffer(nameLen);
          
          // First character, lower case
          int i = 0;
          while (i < nameLen
!                 && !Character.isJavaIdentifierStart(nameArray[i])) {
              i++;
          }
          if (i < nameLen) {
***************
*** 336,342 ****
  
              // if this is a bad char, skip it a remember to capitalize
next
              // good character we encounter
!             if( !Character.isLetterOrDigit(c)) {
                  wordStart = true;
                  continue;
              }
--- 336,342 ----
  
              // if this is a bad char, skip it a remember to capitalize
next
              // good character we encounter
!             if( !Character.isJavaIdentifierPart(c)) {
                  wordStart = true;
                  continue;
              }


Dave Dunkin

Mime
View raw message