You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2003/06/05 23:46:18 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl XMLEntityScanner.java XML11EntityScanner.java

neilg       2003/06/05 14:46:18

  Modified:    java/src/org/apache/xerces/impl XMLEntityScanner.java
                        XML11EntityScanner.java
  Log:
  add a scanNCName function which may be used to scan names which are known must be NCNames
  
  Revision  Changes    Path
  1.16      +85 -1     xml-xerces/java/src/org/apache/xerces/impl/XMLEntityScanner.java
  
  Index: XMLEntityScanner.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityScanner.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XMLEntityScanner.java	8 May 2003 20:11:54 -0000	1.15
  +++ XMLEntityScanner.java	5 Jun 2003 21:46:18 -0000	1.16
  @@ -445,6 +445,90 @@
       } // scanName():String
   
       /**
  +     * Returns a string matching the NCName production appearing immediately
  +     * on the input as a symbol, or null if no NCName string is present.
  +     * <p>
  +     * <strong>Note:</strong> The NCName characters are consumed.
  +     * <p>
  +     * <strong>Note:</strong> The string returned must be a symbol. The
  +     * SymbolTable can be used for this purpose.
  +     *
  +     * @throws IOException  Thrown if i/o error occurs.
  +     * @throws EOFException Thrown on end of file.
  +     *
  +     * @see org.apache.xerces.util.SymbolTable
  +     * @see org.apache.xerces.util.XMLChar#isNCName
  +     * @see org.apache.xerces.util.XMLChar#isNCNameStart
  +     */
  +    public String scanNCName() throws IOException {
  +        if (DEBUG_BUFFER) {
  +            System.out.print("(scanNCName: ");
  +            XMLEntityManager.print(fCurrentEntity);
  +            System.out.println();
  +        }
  +
  +        // load more characters, if needed
  +        if (fCurrentEntity.position == fCurrentEntity.count) {
  +            load(0, true);
  +        }
  +
  +        // scan name
  +        int offset = fCurrentEntity.position;
  +        if (XMLChar.isNCNameStart(fCurrentEntity.ch[offset])) {
  +            if (++fCurrentEntity.position == fCurrentEntity.count) {
  +                fCurrentEntity.ch[0] = fCurrentEntity.ch[offset];
  +                offset = 0;
  +                if (load(1, false)) {
  +                    fCurrentEntity.columnNumber++;
  +                    String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
  +                    if (DEBUG_BUFFER) {
  +                        System.out.print(")scanNCName: ");
  +                        XMLEntityManager.print(fCurrentEntity);
  +                        System.out.println(" -> "+String.valueOf(symbol));
  +                    }
  +                    return symbol;
  +                }
  +            }
  +            while (XMLChar.isNCName(fCurrentEntity.ch[fCurrentEntity.position])) {
  +                if (++fCurrentEntity.position == fCurrentEntity.count) {
  +                    int length = fCurrentEntity.position - offset;
  +                    if (length == fBufferSize) {
  +                        // bad luck we have to resize our buffer
  +                        char[] tmp = new char[fBufferSize * 2];
  +                        System.arraycopy(fCurrentEntity.ch, offset,
  +                                         tmp, 0, length);
  +                        fCurrentEntity.ch = tmp;
  +                        fBufferSize *= 2;
  +                    }
  +                    else {
  +                        System.arraycopy(fCurrentEntity.ch, offset,
  +                                         fCurrentEntity.ch, 0, length);
  +                    }
  +                    offset = 0;
  +                    if (load(length, false)) {
  +                        break;
  +                    }
  +                }
  +            }
  +        }
  +        int length = fCurrentEntity.position - offset;
  +        fCurrentEntity.columnNumber += length;
  +
  +        // return name
  +        String symbol = null;
  +        if (length > 0) {
  +            symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
  +        }
  +        if (DEBUG_BUFFER) {
  +            System.out.print(")scanNCName: ");
  +            XMLEntityManager.print(fCurrentEntity);
  +            System.out.println(" -> "+String.valueOf(symbol));
  +        }
  +        return symbol;
  +
  +    } // scanNCName():String
  +
  +    /**
        * Scans a qualified name from the input, setting the fields of the
        * QName structure appropriately.
        * <p>
  
  
  
  1.4       +70 -1     xml-xerces/java/src/org/apache/xerces/impl/XML11EntityScanner.java
  
  Index: XML11EntityScanner.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XML11EntityScanner.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XML11EntityScanner.java	10 Apr 2003 19:54:12 -0000	1.3
  +++ XML11EntityScanner.java	5 Jun 2003 21:46:18 -0000	1.4
  @@ -282,6 +282,75 @@
       } // scanName():String
   
       /**
  +     * Returns a string matching the NCName production appearing immediately
  +     * on the input as a symbol, or null if no NCName string is present.
  +     * <p>
  +     * <strong>Note:</strong> The NCName characters are consumed.
  +     * <p>
  +     * <strong>Note:</strong> The string returned must be a symbol. The
  +     * SymbolTable can be used for this purpose.
  +     *
  +     * @throws IOException  Thrown if i/o error occurs.
  +     * @throws EOFException Thrown on end of file.
  +     *
  +     * @see org.apache.xerces.util.SymbolTable
  +     * @see org.apache.xerces.util.XML11Char#isXML11NCName
  +     * @see org.apache.xerces.util.XML11Char#isXML11NCNameStart
  +     */
  +    public String scanNCName() throws IOException {
  +
  +        // load more characters, if needed
  +        if (fCurrentEntity.position == fCurrentEntity.count) {
  +            load(0, true);
  +        }
  +
  +        // scan name
  +        int offset = fCurrentEntity.position;
  +        if (XML11Char.isXML11NCNameStart(fCurrentEntity.ch[offset])) {
  +            if (++fCurrentEntity.position == fCurrentEntity.count) {
  +                fCurrentEntity.ch[0] = fCurrentEntity.ch[offset];
  +                offset = 0;
  +                if (load(1, false)) {
  +                    fCurrentEntity.columnNumber++;
  +                    String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
  +                    return symbol;
  +                }
  +            }
  +            while (XML11Char.isXML11NCName(fCurrentEntity.ch[fCurrentEntity.position])) {
  +                if (++fCurrentEntity.position == fCurrentEntity.count) {
  +                    int length = fCurrentEntity.position - offset;
  +                    if (length == fBufferSize) {
  +                        // bad luck we have to resize our buffer
  +                        char[] tmp = new char[fBufferSize * 2];
  +                        System.arraycopy(fCurrentEntity.ch, offset,
  +                                         tmp, 0, length);
  +                        fCurrentEntity.ch = tmp;
  +                        fBufferSize *= 2;
  +                    }
  +                    else {
  +                        System.arraycopy(fCurrentEntity.ch, offset,
  +                                         fCurrentEntity.ch, 0, length);
  +                    }
  +                    offset = 0;
  +                    if (load(length, false)) {
  +                        break;
  +                    }
  +                }
  +            }
  +        }
  +        int length = fCurrentEntity.position - offset;
  +        fCurrentEntity.columnNumber += length;
  +
  +        // return name
  +        String symbol = null;
  +        if (length > 0) {
  +            symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
  +        }
  +        return symbol;
  +
  +    } // scanNCName():String
  +
  +    /**
        * Scans a qualified name from the input, setting the fields of the
        * QName structure appropriately.
        * <p>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org