Hi,

Please find attached patch for class XMLChar. I have implemented the REVISIT for 
NCNAME content validation.

Cheers,
Rahul.

Sun Microsystems, Inc.

XMLChar.java

Index: XMLChar.java
===================================================================
RCS file: /home/cvspublic/xml-xerces/java/src/org/apache/xerces/util/XMLChar.java,v
retrieving revision 1.3
diff -u -w -r1.3 XMLChar.java
--- XMLChar.java        2001/08/24 23:09:47     1.3
+++ XMLChar.java        2001/10/17 11:00:14
@@ -77,6 +77,7 @@
  * @author Andy Clark, IBM
  * @author Eric Ye, IBM
  * @author Arnaud  Le Hors, IBM
+ * @author Rahul Srivastava, Sun Microsystems Inc.
  *
  * @version $Id: XMLChar.java,v 1.3 2001/08/24 23:09:47 elena Exp $
  */
@@ -114,6 +115,12 @@
      */
     public static final int MASK_CONTENT = 0x20;
 
+    /** NCName start character mask. */
+    public static final int MASK_NCNAME_START = 0x40;
+
+    /** NCName character mask. */
+    public static final int MASK_NCNAME = 0x80;
+
     //
     // Static initialization
     //
@@ -155,6 +162,25 @@
         };
 
         //
+        // production[5] of Namespaces in XML recommendation
+        // [5] NCNameChar ::= Letter | Digit | '.' | '-' | '_' |
+        //                    CombiningChar | Extender
+        //
+
+        int ncNameChar[] = { 
+            0x002D, 0x002E // '-' and '.'
+        };
+
+        //
+        // production[4] of Namespaces in XML recommendation
+        // [4] NCName ::= (Letter | '_') (NCNameChar)*
+        //
+
+        int ncNameStartChar[] = { 
+            0x005F // '_'
+        };
+
+        //
         // [13] PubidChar ::= #x20 | 0xD | 0xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
         //
 
@@ -349,6 +375,45 @@
             CHARS[extenderChar[i]] |= MASK_NAME;
         }
 
+        // set ncName start characters
+        for (int i = 0; i < ncNameStartChar.length; i++) {
+            CHARS[ncNameStartChar[i]] |= MASK_NCNAME_START | MASK_NCNAME;
+        }
+        for (int i = 0; i < letterRange.length; i += 2) {
+            for (int j = letterRange[i]; j <= letterRange[i + 1]; j++) {
+                CHARS[j] |= MASK_NCNAME_START | MASK_NCNAME;
+            }
+        }
+        for (int i = 0; i < letterChar.length; i++) {
+            CHARS[letterChar[i]] |= MASK_NCNAME_START | MASK_NCNAME;
+        }
+
+        // set ncName characters
+        for (int i = 0; i < ncNameChar.length; i++) {
+            CHARS[ncNameChar[i]] |= MASK_NCNAME;
+        }
+        for (int i = 0; i < digitRange.length; i += 2) {
+            for (int j = digitRange[i]; j <= digitRange[i + 1]; j++) {
+                CHARS[j] |= MASK_NCNAME;
+            }
+        }
+        for (int i = 0; i < combiningCharRange.length; i += 2) {
+            for (int j = combiningCharRange[i]; j <= combiningCharRange[i + 1]; j++) {
+                CHARS[j] |= MASK_NCNAME;
+            }
+        }
+        for (int i = 0; i < combiningCharChar.length; i++) {
+            CHARS[combiningCharChar[i]] |= MASK_NCNAME;
+        }
+        for (int i = 0; i < extenderRange.length; i += 2) {
+            for (int j = extenderRange[i]; j <= extenderRange[i + 1]; j++) {
+                CHARS[j] |= MASK_NCNAME;
+            }
+        }
+        for (int i = 0; i < extenderChar.length; i++) {
+            CHARS[extenderChar[i]] |= MASK_NCNAME;
+        }
+
         // set Pubid characters
         for (int i = 0; i < pubidChar.length; i++) {
             CHARS[pubidChar[i]] |= MASK_PUBID;
@@ -499,6 +564,28 @@
     } // isName(int):boolean
 
      /**
+     * Returns true if the specified character is a valid NCName start
+     * character as defined by production [4] in Namespaces in XML
+     * recommendation.
+     *
+     * @param c The character to check.
+     */
+    public static boolean isNCNameStart(int c) {
+        return c < 0x10000 && (CHARS[c] & MASK_NCNAME_START) != 0;
+    } // isNCNameStart(int):boolean
+
+    /**
+     * Returns true if the specified character is a valid NCName
+     * character as defined by production [5] in Namespaces in XML
+     * recommendation.
+     *
+     * @param c The character to check.
+     */
+    public static boolean isNCName(int c) {
+        return c < 0x10000 && (CHARS[c] & MASK_NCNAME) != 0;
+    } // isNCName(int):boolean
+
+     /**
      * Returns true if the specified character is a valid Pubid
      * character as defined by production [13] in the XML 1.0
      * specification.
@@ -534,7 +621,6 @@
         return true;
     } // isValidName(String):boolean
     
-
     /*
      * from the namespace rec
      * [4] NCName ::= (Letter | '_') (NCNameChar)*
@@ -546,10 +632,20 @@
      * @param name string to check
      * @return true if name is a valid NCName
      */
-    public static boolean isValidNCName(String name) {
-        //REVISIT: implement this method!!
-        return true;
+    public static boolean isValidNCName(String ncName) {
+        if (ncName.length() == 0)
+            return false;
+        char ch = ncName.charAt(0);
+        if( isNCNameStart(ch) == false)
+           return false;
+        for (int i = 1; i < ncName.length(); i++ ) {
+           ch = ncName.charAt(i);
+           if( isNCName( ch ) == false ){
+              return false;
+           }
     }
+        return true;
+    } // isValidNCName(String):boolean
 
     /*
      * [7] Nmtoken ::= (NameChar)+

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to