jaxp/src/com/sun/org/apache/xerces/internal/impl/XML11EntityScanner.java
author joehw
Sun, 05 Jan 2014 21:00:00 -0800
changeset 22140 f2634f2bc36c
parent 12457 c348e06f0e82
child 25264 040625ce9b72
permissions -rw-r--r--
8027359: XML parser returns incorrect parsing results Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * The Apache Software License, Version 1.1
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * Copyright (c) 1999-2002 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * All rights reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 * Redistribution and use in source and binary forms, with or without
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * modification, are permitted provided that the following conditions
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * are met:
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * 1. Redistributions of source code must retain the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 *    notice, this list of conditions and the following disclaimer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * 2. Redistributions in binary form must reproduce the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 *    notice, this list of conditions and the following disclaimer in
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 *    the documentation and/or other materials provided with the
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 *    distribution.
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 * 3. The end-user documentation included with the redistribution,
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
 *    if any, must include the following acknowledgment:
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
 *       "This product includes software developed by the
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
 *        Apache Software Foundation (http://www.apache.org/)."
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
 *    Alternately, this acknowledgment may appear in the software itself,
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 *    if and wherever such third-party acknowledgments normally appear.
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * 4. The names "Xerces" and "Apache Software Foundation" must
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 *    not be used to endorse or promote products derived from this
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 *    software without prior written permission. For written
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *    permission, please contact apache@apache.org.
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * 5. Products derived from this software may not be called "Apache",
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 *    nor may "Apache" appear in their name, without prior written
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 *    permission of the Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * SUCH DAMAGE.
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * ====================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * This software consists of voluntary contributions made by many
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * individuals on behalf of the Apache Software Foundation and was
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * originally based on software copyright (c) 1999, International
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * Business Machines, Inc., http://www.apache.org.  For more
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * information on the Apache Software Foundation, please see
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * <http://www.apache.org/>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
package com.sun.org.apache.xerces.internal.impl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
    65
import com.sun.org.apache.xerces.internal.util.XML11Char;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
import com.sun.org.apache.xerces.internal.util.XMLChar;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
import com.sun.org.apache.xerces.internal.xni.QName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
import com.sun.org.apache.xerces.internal.xni.XMLString;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
    70
import java.io.IOException;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
 * Implements the entity scanner methods in
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
 * the context of XML 1.1.
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
 * @xerces.internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
 * @author Michael Glavassevich, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
 * @author Neil Graham, IBM
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
    80
 * @version $Id: XML11EntityScanner.java,v 1.5 2010-11-01 04:39:40 joehw Exp $
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
public class XML11EntityScanner
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    extends XMLEntityScanner {
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
    // Constructors
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    /** Default constructor. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    public XML11EntityScanner() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        super();
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    } // <init>()
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    // XMLEntityScanner methods
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
     * Returns the next character on the input.
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
     * <strong>Note:</strong> The character is <em>not</em> consumed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    public int peekChar() throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   111
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
        // peek at character
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
        int c = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
        // return peeked character
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        if (fCurrentEntity.isExternal()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
            return (c != '\r' && c != 0x85 && c != 0x2028) ? c : '\n';
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
            return c;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    } // peekChar():int
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     * Returns the next character on the input.
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
     * <strong>Note:</strong> The character is consumed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    public int scanChar() throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   139
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
        // scan character
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
        int c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
        boolean external = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
        if (c == '\n' ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
            ((c == '\r' || c == 0x85 || c == 0x2028) && (external = fCurrentEntity.isExternal()))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
            fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
            fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
            if (fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
                fCurrentEntity.ch[0] = (char)c;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   151
                load(1, false, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
            if (c == '\r' && external) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
                int cc = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
                if (cc != '\n' && cc != 0x85) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
                    fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
            c = '\n';
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
        // return character that was scanned
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
        fCurrentEntity.columnNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
        return c;
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    } // scanChar():int
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
     * Returns a string matching the NMTOKEN production appearing immediately
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
     * on the input as a symbol, or null if NMTOKEN Name string is present.
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
     * <strong>Note:</strong> The NMTOKEN characters are consumed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
     * <strong>Note:</strong> The string returned must be a symbol. The
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
     * SymbolTable can be used for this purpose.
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
     * @see com.sun.org.apache.xerces.internal.util.SymbolTable
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
     * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Name
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
    public String scanNmtoken() throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   186
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        // scan nmtoken
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
        int offset = fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
            char ch = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
            if (XML11Char.isXML11Name(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   197
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   210
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
            else if (XML11Char.isXML11NameHighSurrogate(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   218
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   231
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
                        --fCurrentEntity.startPosition;
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
                        --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
                char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
                if ( !XMLChar.isLowSurrogate(ch2) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
                     !XML11Char.isXML11Name(XMLChar.supplemental(ch, ch2)) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
                    --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   245
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   258
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
        while (true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
        int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
        fCurrentEntity.columnNumber += length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
        // return nmtoken
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        String symbol = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
        if (length > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
            symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        return symbol;
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
    } // scanNmtoken():String
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
     * Returns a string matching the Name production appearing immediately
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
     * on the input as a symbol, or null if no Name string is present.
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
     * <strong>Note:</strong> The Name characters are consumed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
     * <strong>Note:</strong> The string returned must be a symbol. The
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
     * SymbolTable can be used for this purpose.
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
     * @see com.sun.org.apache.xerces.internal.util.SymbolTable
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
     * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Name
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
     * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NameStart
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
    public String scanName() throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   300
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        // scan name
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
        int offset = fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        char ch = fCurrentEntity.ch[offset];
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
        if (XML11Char.isXML11NameStart(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
            if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
                fCurrentEntity.ch[0] = ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
                offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   311
                if (load(1, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
                    fCurrentEntity.columnNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
                    String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
                    return symbol;
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
        else if (XML11Char.isXML11NameHighSurrogate(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
            if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
                fCurrentEntity.ch[0] = ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
                offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   322
                if (load(1, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
                    --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
                    --fCurrentEntity.startPosition;
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
                    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
            char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
            if ( !XMLChar.isLowSurrogate(ch2) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
                 !XML11Char.isXML11NameStart(XMLChar.supplemental(ch, ch2)) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
                --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
                return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
            if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
                fCurrentEntity.ch[0] = ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
                fCurrentEntity.ch[1] = ch2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
                offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   338
                if (load(2, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
                    fCurrentEntity.columnNumber += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
                    String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
                    return symbol;
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
            return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
            ch = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
            if (XML11Char.isXML11Name(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   354
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   367
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
            else if (XML11Char.isXML11NameHighSurrogate(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   375
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   388
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
                        --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
                        --fCurrentEntity.startPosition;
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
                char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
                if ( !XMLChar.isLowSurrogate(ch2) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
                     !XML11Char.isXML11Name(XMLChar.supplemental(ch, ch2)) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
                    --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   402
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   415
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
        while (true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
        int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
        fCurrentEntity.columnNumber += length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
        // return name
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
        String symbol = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
        if (length > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
            symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
        return symbol;
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
    } // scanName():String
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
     * Returns a string matching the NCName production appearing immediately
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
     * on the input as a symbol, or null if no NCName string is present.
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
     * <strong>Note:</strong> The NCName characters are consumed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
     * <strong>Note:</strong> The string returned must be a symbol. The
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
     * SymbolTable can be used for this purpose.
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
     * @see com.sun.org.apache.xerces.internal.util.SymbolTable
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
     * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NCName
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
     * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NCNameStart
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
    public String scanNCName() throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   458
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
        // scan name
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
        int offset = fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
        char ch = fCurrentEntity.ch[offset];
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
        if (XML11Char.isXML11NCNameStart(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
            if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
                fCurrentEntity.ch[0] = ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
                offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   469
                if (load(1, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
                    fCurrentEntity.columnNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
                    String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
                    return symbol;
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
        else if (XML11Char.isXML11NameHighSurrogate(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
            if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
                fCurrentEntity.ch[0] = ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
                offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   480
                if (load(1, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
                    --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
                    --fCurrentEntity.startPosition;
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
                    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
            char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
            if ( !XMLChar.isLowSurrogate(ch2) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
                 !XML11Char.isXML11NCNameStart(XMLChar.supplemental(ch, ch2)) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
                --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
                return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
            if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
                fCurrentEntity.ch[0] = ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
                fCurrentEntity.ch[1] = ch2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
                offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   496
                if (load(2, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
                    fCurrentEntity.columnNumber += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
                    String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
                    return symbol;
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
            return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
            ch = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
            if (XML11Char.isXML11NCName(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   512
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   525
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
            else if (XML11Char.isXML11NameHighSurrogate(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   533
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   546
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
                        --fCurrentEntity.startPosition;
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
                        --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
                char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
                if ( !XMLChar.isLowSurrogate(ch2) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
                     !XML11Char.isXML11NCName(XMLChar.supplemental(ch, ch2)) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
                    --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   560
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   573
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
        while (true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
        int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
        fCurrentEntity.columnNumber += length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
        // return name
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
        String symbol = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
        if (length > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
            symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
        return symbol;
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
    } // scanNCName():String
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
     * Scans a qualified name from the input, setting the fields of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
     * QName structure appropriately.
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
     * <strong>Note:</strong> The qualified name characters are consumed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
     * <strong>Note:</strong> The strings used to set the values of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
     * QName structure must be symbols. The SymbolTable can be used for
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
     * this purpose.
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
     * @param qname The qualified name structure to fill.
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
     * @return Returns true if a qualified name appeared immediately on
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
     *         the input and was scanned, false otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
     * @see com.sun.org.apache.xerces.internal.util.SymbolTable
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
     * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Name
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
     * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NameStart
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
    public boolean scanQName(QName qname) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   622
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
        // scan qualified name
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
        int offset = fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
        char ch = fCurrentEntity.ch[offset];
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
        if (XML11Char.isXML11NCNameStart(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
            if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
                fCurrentEntity.ch[0] = ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
                offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   633
                if (load(1, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
                    fCurrentEntity.columnNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
                    String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
                    qname.setValues(null, name, name, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
                    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
        else if (XML11Char.isXML11NameHighSurrogate(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
            if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
                fCurrentEntity.ch[0] = ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
                offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   645
                if (load(1, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
                    --fCurrentEntity.startPosition;
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
                    --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
                    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
            char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
            if ( !XMLChar.isLowSurrogate(ch2) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
                 !XML11Char.isXML11NCNameStart(XMLChar.supplemental(ch, ch2)) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
                --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
            if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
                fCurrentEntity.ch[0] = ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
                fCurrentEntity.ch[1] = ch2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
                offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   661
                if (load(2, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
                    fCurrentEntity.columnNumber += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
                    String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
                    qname.setValues(null, name, name, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
                    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
        int index = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
        boolean sawIncompleteSurrogatePair = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
            ch = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
            if (XML11Char.isXML11Name(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
                if (ch == ':') {
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
                    if (index != -1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
                    index = fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   686
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
                    if (index != -1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
                        index = index - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   702
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
            else if (XML11Char.isXML11NameHighSurrogate(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   710
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
                    if (index != -1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
                        index = index - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   726
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
                        sawIncompleteSurrogatePair = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
                        --fCurrentEntity.startPosition;
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
                        --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
                char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
                if ( !XMLChar.isLowSurrogate(ch2) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
                     !XML11Char.isXML11Name(XMLChar.supplemental(ch, ch2)) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
                    sawIncompleteSurrogatePair = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
                    --fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
                if (++fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
                    int length = fCurrentEntity.position - offset;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   742
                    invokeListeners(length);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
                    if (length == fCurrentEntity.ch.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
                        // bad luck we have to resize our buffer
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
                        char[] tmp = new char[fCurrentEntity.ch.length << 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
                                         tmp, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
                        fCurrentEntity.ch = tmp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
                        System.arraycopy(fCurrentEntity.ch, offset,
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
                                         fCurrentEntity.ch, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
                    if (index != -1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
                        index = index - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
                    offset = 0;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   758
                    if (load(length, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
        while (true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
        int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
        fCurrentEntity.columnNumber += length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
        if (length > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
            String prefix = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
            String localpart = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
            String rawname = fSymbolTable.addSymbol(fCurrentEntity.ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
                                                    offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
            if (index != -1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
                int prefixLength = index - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
                prefix = fSymbolTable.addSymbol(fCurrentEntity.ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
                                                    offset, prefixLength);
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
                int len = length - prefixLength - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
                int startLocal = index +1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
                if (!XML11Char.isXML11NCNameStart(fCurrentEntity.ch[startLocal]) &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
                    (!XML11Char.isXML11NameHighSurrogate(fCurrentEntity.ch[startLocal]) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
                    sawIncompleteSurrogatePair)){
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
                    fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
                                               "IllegalQName",
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
                                               null,
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
                                               XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
                localpart = fSymbolTable.addSymbol(fCurrentEntity.ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
                                                   index + 1, len);
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
                localpart = rawname;
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
            qname.setValues(prefix, localpart, rawname, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
            return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
    } // scanQName(QName):boolean
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
     * Scans a range of parsed character data, setting the fields of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
     * XMLString structure, appropriately.
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
     * <strong>Note:</strong> The characters are consumed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
     * <strong>Note:</strong> This method does not guarantee to return
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
     * the longest run of parsed character data. This method may return
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
     * before markup due to reaching the end of the input buffer or any
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
     * other reason.
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
     * <strong>Note:</strong> The fields contained in the XMLString
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
     * structure are not guaranteed to remain valid upon subsequent calls
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
     * to the entity scanner. Therefore, the caller is responsible for
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
     * immediately using the returned character data or making a copy of
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
     * the character data.
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
     * @param content The content structure to fill.
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
     * @return Returns the next character on the input, if known. This
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
     *         value may be -1 but this does <em>note</em> designate
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
     *         end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
    public int scanContent(XMLString content) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   835
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
        else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
            fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   839
            load(1, false, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
            fCurrentEntity.position = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
            fCurrentEntity.startPosition = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
        // normalize newlines
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
        int offset = fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
        int c = fCurrentEntity.ch[offset];
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
        int newlines = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
        boolean external = fCurrentEntity.isExternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
        if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
            do {
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
                c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
                if ((c == '\r' ) && external) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
                    newlines++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
                    fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
                    fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
                    if (fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
                        offset = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
                        fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
                        fCurrentEntity.position = newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
                        fCurrentEntity.startPosition = newlines;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   861
                        if (load(newlines, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
                            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
                    int cc = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
                    if (cc == '\n' || cc == 0x85) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
                        fCurrentEntity.position++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
                        offset++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
                    /*** NEWLINE NORMALIZATION ***/
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
                        newlines++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
                else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
                    newlines++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
                    fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
                    fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
                    if (fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
                        offset = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
                        fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
                        fCurrentEntity.position = newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
                        fCurrentEntity.startPosition = newlines;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   884
                        if (load(newlines, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
                            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
                    fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
            } while (fCurrentEntity.position < fCurrentEntity.count - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
            for (int i = offset; i < fCurrentEntity.position; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
                fCurrentEntity.ch[i] = '\n';
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
            int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
            if (fCurrentEntity.position == fCurrentEntity.count - 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
                content.setValues(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
                return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
        // inner loop, scanning for content
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
        if (external) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
            while (fCurrentEntity.position < fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
                c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
                if (!XML11Char.isXML11Content(c) || c == 0x85 || c == 0x2028) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
                    fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
            while (fCurrentEntity.position < fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
                c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
                // In internal entities control characters are allowed to appear unescaped.
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
                if (!XML11Char.isXML11InternalEntityContent(c)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
                    fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
        int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
        fCurrentEntity.columnNumber += length - newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
        content.setValues(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
        // return next character
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
        if (fCurrentEntity.position != fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
            c = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
            // REVISIT: Does this need to be updated to fix the
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
            //          #x0D ^#x0A newline normalization problem? -Ac
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
            if ((c == '\r' || c == 0x85 || c == 0x2028) && external) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
                c = '\n';
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
            c = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
        return c;
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
    } // scanContent(XMLString):int
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
     * Scans a range of attribute value data, setting the fields of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
     * XMLString structure, appropriately.
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
     * <strong>Note:</strong> The characters are consumed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
     * <strong>Note:</strong> This method does not guarantee to return
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
     * the longest run of attribute value data. This method may return
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
     * before the quote character due to reaching the end of the input
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
     * buffer or any other reason.
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
     * <strong>Note:</strong> The fields contained in the XMLString
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
     * structure are not guaranteed to remain valid upon subsequent calls
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
     * to the entity scanner. Therefore, the caller is responsible for
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
     * immediately using the returned character data or making a copy of
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
     * the character data.
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
     * @param quote   The quote character that signifies the end of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
     *                attribute value data.
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
     * @param content The content structure to fill.
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
     * @return Returns the next character on the input, if known. This
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
     *         value may be -1 but this does <em>note</em> designate
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
     *         end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
    public int scanLiteral(int quote, XMLString content)
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
        throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   976
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
        else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
            fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
   980
            load(1, false, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
            fCurrentEntity.startPosition = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
            fCurrentEntity.position = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
        // normalize newlines
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
        int offset = fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
        int c = fCurrentEntity.ch[offset];
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
        int newlines = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
        boolean external = fCurrentEntity.isExternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
        if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
            do {
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
                c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
                if ((c == '\r' ) && external) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
                    newlines++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
                    fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
                    fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
                    if (fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
                        offset = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
                        fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
                        fCurrentEntity.position = newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
                        fCurrentEntity.startPosition = newlines;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1002
                        if (load(newlines, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
                            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
                    int cc = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
                    if (cc == '\n' || cc == 0x85) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
                        fCurrentEntity.position++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
                        offset++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
                    /*** NEWLINE NORMALIZATION ***/
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
                        newlines++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
                else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
                    newlines++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
                    fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
                    fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
                    if (fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
                        offset = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
                        fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
                        fCurrentEntity.position = newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
                        fCurrentEntity.startPosition = newlines;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1025
                        if (load(newlines, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
                            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
                    fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
            } while (fCurrentEntity.position < fCurrentEntity.count - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
            for (int i = offset; i < fCurrentEntity.position; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
                fCurrentEntity.ch[i] = '\n';
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
            int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
            if (fCurrentEntity.position == fCurrentEntity.count - 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
                content.setValues(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
                return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
        // scan literal value
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
        if (external) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
            while (fCurrentEntity.position < fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
                c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
                if (c == quote || c == '%' || !XML11Char.isXML11Content(c)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
                    || c == 0x85 || c == 0x2028) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
                    fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
            while (fCurrentEntity.position < fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
                c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
                // In internal entities control characters are allowed to appear unescaped.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
                if ((c == quote && !fCurrentEntity.literal)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
                    || c == '%' || !XML11Char.isXML11InternalEntityContent(c)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
                    fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
        int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
        fCurrentEntity.columnNumber += length - newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
        content.setValues(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
        // return next character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
        if (fCurrentEntity.position != fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
            c = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
            // NOTE: We don't want to accidentally signal the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
            //       end of the literal if we're expanding an
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
            //       entity appearing in the literal. -Ac
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
            if (c == quote && fCurrentEntity.literal) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
                c = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
            c = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
        return c;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
    } // scanLiteral(int,XMLString):int
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
     * Scans a range of character data up to the specicied delimiter,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
     * setting the fields of the XMLString structure, appropriately.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
     * <strong>Note:</strong> The characters are consumed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
     * <strong>Note:</strong> This assumes that the internal buffer is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
     * at least the same size, or bigger, than the length of the delimiter
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
     * and that the delimiter contains at least one character.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
     * <strong>Note:</strong> This method does not guarantee to return
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
     * the longest run of character data. This method may return before
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
     * the delimiter due to reaching the end of the input buffer or any
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
     * other reason.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
     * <strong>Note:</strong> The fields contained in the XMLString
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
     * structure are not guaranteed to remain valid upon subsequent calls
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
     * to the entity scanner. Therefore, the caller is responsible for
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
     * immediately using the returned character data or making a copy of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
     * the character data.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
     * @param delimiter The string that signifies the end of the character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
     *                  data to be scanned.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
     * @param data      The data structure to fill.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
     * @return Returns true if there is more data to scan, false otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
    public boolean scanData(String delimiter, XMLStringBuffer buffer)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
        throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
        boolean done = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
        int delimLen = delimiter.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
        char charAt0 = delimiter.charAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
        boolean external = fCurrentEntity.isExternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
            // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
            if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1128
                load(0, true, false);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
            boolean bNextEntity = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
            while ((fCurrentEntity.position >= fCurrentEntity.count - delimLen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
                && (!bNextEntity))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
              System.arraycopy(fCurrentEntity.ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
                               fCurrentEntity.position,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
                               fCurrentEntity.ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
                               0,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
                               fCurrentEntity.count - fCurrentEntity.position);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1142
              bNextEntity = load(fCurrentEntity.count - fCurrentEntity.position, false, false);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
              fCurrentEntity.position = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
              fCurrentEntity.startPosition = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
            if (fCurrentEntity.position >= fCurrentEntity.count - delimLen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
                // something must be wrong with the input:  e.g., file ends  an unterminated comment
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
                int length = fCurrentEntity.count - fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
                buffer.append (fCurrentEntity.ch, fCurrentEntity.position, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
                fCurrentEntity.columnNumber += fCurrentEntity.count;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
                fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
                fCurrentEntity.position = fCurrentEntity.count;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
                fCurrentEntity.startPosition = fCurrentEntity.count;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1155
                load(0,true, false);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
            // normalize newlines
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
            int offset = fCurrentEntity.position;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
            int c = fCurrentEntity.ch[offset];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
            int newlines = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
            if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
                do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
                    c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
                    if ((c == '\r' ) && external) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
                        newlines++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
                        fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
                        fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
                        if (fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
                            offset = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
                            fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
                            fCurrentEntity.position = newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
                            fCurrentEntity.startPosition = newlines;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1175
                            if (load(newlines, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
                                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
                        int cc = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
                        if (cc == '\n' || cc == 0x85) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
                            fCurrentEntity.position++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
                            offset++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
                        /*** NEWLINE NORMALIZATION ***/
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
                        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
                            newlines++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
                    else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
                        newlines++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
                        fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
                        fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
                        if (fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
                            offset = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
                            fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
                            fCurrentEntity.position = newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
                            fCurrentEntity.startPosition = newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
                            fCurrentEntity.count = newlines;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1199
                            if (load(newlines, false, true)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
                                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
                        fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
                } while (fCurrentEntity.position < fCurrentEntity.count - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
                for (int i = offset; i < fCurrentEntity.position; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
                    fCurrentEntity.ch[i] = '\n';
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
                int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
                if (fCurrentEntity.position == fCurrentEntity.count - 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
                    buffer.append(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
                    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
            // iterate over buffer looking for delimiter
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
            if (external) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
                OUTER: while (fCurrentEntity.position < fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
                    c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
                    if (c == charAt0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
                        // looks like we just hit the delimiter
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
                        int delimOffset = fCurrentEntity.position - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
                        for (int i = 1; i < delimLen; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
                            if (fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
                                fCurrentEntity.position -= i;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
                                break OUTER;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
                            c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
                            if (delimiter.charAt(i) != c) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
                                fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
                                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
                         }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
                         if (fCurrentEntity.position == delimOffset + delimLen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
                            done = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
                            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
                         }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
                    else if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
                        fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
                    // In external entities control characters cannot appear
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
                    // as literals so do not skip over them.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
                    else if (!XML11Char.isXML11ValidLiteral(c)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
                        fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
                        int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
                        fCurrentEntity.columnNumber += length - newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
                        buffer.append(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
                        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
                OUTER: while (fCurrentEntity.position < fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
                    c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
                    if (c == charAt0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
                        // looks like we just hit the delimiter
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
                        int delimOffset = fCurrentEntity.position - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
                        for (int i = 1; i < delimLen; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
                            if (fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
                                fCurrentEntity.position -= i;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
                                break OUTER;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
                            c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
                            if (delimiter.charAt(i) != c) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
                                fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
                                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
                        if (fCurrentEntity.position == delimOffset + delimLen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
                            done = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
                            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
                    else if (c == '\n') {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
                        fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1283
                    // Control characters are allowed to appear as literals
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
                    // in internal entities.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1285
                    else if (!XML11Char.isXML11Valid(c)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
                        fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
                        int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
                        fCurrentEntity.columnNumber += length - newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
                        buffer.append(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
                        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
            int length = fCurrentEntity.position - offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
            fCurrentEntity.columnNumber += length - newlines;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
            if (done) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
                length -= delimLen;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
            buffer.append(fCurrentEntity.ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
            // return true if string was skipped
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
        } while (!done);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
        return !done;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
    } // scanData(String,XMLString)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
     * Skips a character appearing immediately on the input.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
     * <strong>Note:</strong> The character is consumed only if it matches
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
     * the specified character.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
     * @param c The character to skip.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
     * @return Returns true if the character was skipped.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
    public boolean skipChar(int c) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1324
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
        // skip character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
        int cc = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
        if (cc == c) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
            fCurrentEntity.position++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1331
            if (c == '\n') {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
                fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
                fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
                fCurrentEntity.columnNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
            return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1339
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
        else if (c == '\n' && ((cc == 0x2028 || cc == 0x85) && fCurrentEntity.isExternal())) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
            fCurrentEntity.position++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
            fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
            fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
            return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1346
        else if (c == '\n' && (cc == '\r' ) && fCurrentEntity.isExternal()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1347
            // handle newlines
7f561c08de6b Initial load
duke
parents:
diff changeset
  1348
            if (fCurrentEntity.position == fCurrentEntity.count) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1349
                fCurrentEntity.ch[0] = (char)cc;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1350
                load(1, false, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
            int ccc = fCurrentEntity.ch[++fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
            if (ccc == '\n' || ccc == 0x85) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
                fCurrentEntity.position++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
            fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1357
            fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1358
            return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
        // character was not skipped
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
    } // skipChar(int):boolean
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1367
     * Skips space characters appearing immediately on the input.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1369
     * <strong>Note:</strong> The characters are consumed only if they are
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
     * space characters.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
     * @return Returns true if at least one space character was skipped.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1373
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1374
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1375
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1376
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1377
     * @see com.sun.org.apache.xerces.internal.util.XMLChar#isSpace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1378
     * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Space
7f561c08de6b Initial load
duke
parents:
diff changeset
  1379
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1380
    public boolean skipSpaces() throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1381
7f561c08de6b Initial load
duke
parents:
diff changeset
  1382
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1383
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1384
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1385
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1386
7f561c08de6b Initial load
duke
parents:
diff changeset
  1387
7f561c08de6b Initial load
duke
parents:
diff changeset
  1388
        //we are doing this check only in skipSpace() because it is called by
7f561c08de6b Initial load
duke
parents:
diff changeset
  1389
        //fMiscDispatcher and we want the parser to exit gracefully when document
7f561c08de6b Initial load
duke
parents:
diff changeset
  1390
        //is well-formed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1391
        //it is possible that end of document is reached and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1392
        //fCurrentEntity becomes null
7f561c08de6b Initial load
duke
parents:
diff changeset
  1393
        //nothing was read so entity changed  'false' should be returned.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1394
        if(fCurrentEntity == null){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1395
            return false ;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1396
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1397
7f561c08de6b Initial load
duke
parents:
diff changeset
  1398
        // skip spaces
7f561c08de6b Initial load
duke
parents:
diff changeset
  1399
        int c = fCurrentEntity.ch[fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1400
7f561c08de6b Initial load
duke
parents:
diff changeset
  1401
        // External --  Match: S + 0x85 + 0x2028, and perform end of line normalization
7f561c08de6b Initial load
duke
parents:
diff changeset
  1402
        if (fCurrentEntity.isExternal()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1403
            if (XML11Char.isXML11Space(c)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1404
                do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1405
                    boolean entityChanged = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1406
                    // handle newlines
7f561c08de6b Initial load
duke
parents:
diff changeset
  1407
                    if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1408
                        fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1409
                        fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1410
                        if (fCurrentEntity.position == fCurrentEntity.count - 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1411
                            fCurrentEntity.ch[0] = (char)c;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1412
                            entityChanged = load(1, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1413
                            if (!entityChanged) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1414
                                // the load change the position to be 1,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1415
                                // need to restore it when entity not changed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1416
                                fCurrentEntity.startPosition = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1417
                                fCurrentEntity.position = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1418
                            } else if(fCurrentEntity == null){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1419
                                return true ;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1420
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1421
7f561c08de6b Initial load
duke
parents:
diff changeset
  1422
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1423
                        if (c == '\r') {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1424
                            // REVISIT: Does this need to be updated to fix the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1425
                            //          #x0D ^#x0A newline normalization problem? -Ac
7f561c08de6b Initial load
duke
parents:
diff changeset
  1426
                            int cc = fCurrentEntity.ch[++fCurrentEntity.position];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1427
                            if (cc != '\n' && cc != 0x85 ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1428
                                fCurrentEntity.position--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1429
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1430
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1431
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1432
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1433
                        fCurrentEntity.columnNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1434
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1435
                    // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1436
                    if (!entityChanged)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1437
                        fCurrentEntity.position++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1438
                    if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1439
                        load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1440
7f561c08de6b Initial load
duke
parents:
diff changeset
  1441
                        if(fCurrentEntity == null){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1442
                        return true ;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1443
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1444
7f561c08de6b Initial load
duke
parents:
diff changeset
  1445
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1446
                } while (XML11Char.isXML11Space(c = fCurrentEntity.ch[fCurrentEntity.position]));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1447
                return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1448
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1449
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1450
        // Internal -- Match: S (only)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1451
        else if (XMLChar.isSpace(c)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1452
            do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1453
                boolean entityChanged = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1454
                // handle newlines
7f561c08de6b Initial load
duke
parents:
diff changeset
  1455
                if (c == '\n') {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1456
                    fCurrentEntity.lineNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1457
                    fCurrentEntity.columnNumber = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1458
                    if (fCurrentEntity.position == fCurrentEntity.count - 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1459
                        fCurrentEntity.ch[0] = (char)c;
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1460
                        entityChanged = load(1, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1461
                        if (!entityChanged) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1462
                            // the load change the position to be 1,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1463
                            // need to restore it when entity not changed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1464
                            fCurrentEntity.startPosition = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1465
                            fCurrentEntity.position = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1466
                        } else if(fCurrentEntity == null){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1467
                        return true ;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1468
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1469
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1470
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1471
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1472
                    fCurrentEntity.columnNumber++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1473
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1474
                // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1475
                if (!entityChanged)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1476
                    fCurrentEntity.position++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1477
                if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1478
                    load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1479
7f561c08de6b Initial load
duke
parents:
diff changeset
  1480
                    if(fCurrentEntity == null){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1481
                        return true ;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1482
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1483
7f561c08de6b Initial load
duke
parents:
diff changeset
  1484
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1485
            } while (XMLChar.isSpace(c = fCurrentEntity.ch[fCurrentEntity.position]));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1486
            return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1487
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1488
7f561c08de6b Initial load
duke
parents:
diff changeset
  1489
        // no spaces were found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1490
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1491
7f561c08de6b Initial load
duke
parents:
diff changeset
  1492
    } // skipSpaces():boolean
7f561c08de6b Initial load
duke
parents:
diff changeset
  1493
7f561c08de6b Initial load
duke
parents:
diff changeset
  1494
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1495
     * Skips the specified string appearing immediately on the input.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1496
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1497
     * <strong>Note:</strong> The characters are consumed only if they are
7f561c08de6b Initial load
duke
parents:
diff changeset
  1498
     * space characters.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1499
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1500
     * @param s The string to skip.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1501
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1502
     * @return Returns true if the string was skipped.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1503
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1504
     * @throws IOException  Thrown if i/o error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1505
     * @throws EOFException Thrown on end of file.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1506
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1507
    public boolean skipString(String s) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1508
7f561c08de6b Initial load
duke
parents:
diff changeset
  1509
        // load more characters, if needed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1510
        if (fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1511
            load(0, true, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1512
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1513
7f561c08de6b Initial load
duke
parents:
diff changeset
  1514
        // skip string
7f561c08de6b Initial load
duke
parents:
diff changeset
  1515
        final int length = s.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1516
        for (int i = 0; i < length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1517
            char c = fCurrentEntity.ch[fCurrentEntity.position++];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1518
            if (c != s.charAt(i)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1519
                fCurrentEntity.position -= i + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1520
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1521
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1522
            if (i < length - 1 && fCurrentEntity.position == fCurrentEntity.count) {
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1523
                invokeListeners(0);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1524
                System.arraycopy(fCurrentEntity.ch, fCurrentEntity.count - i - 1, fCurrentEntity.ch, 0, i + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1525
                // REVISIT: Can a string to be skipped cross an
7f561c08de6b Initial load
duke
parents:
diff changeset
  1526
                //          entity boundary? -Ac
22140
f2634f2bc36c 8027359: XML parser returns incorrect parsing results
joehw
parents: 12457
diff changeset
  1527
                if (load(i + 1, false, false)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1528
                    fCurrentEntity.startPosition -= i + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1529
                    fCurrentEntity.position -= i + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1530
                    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1531
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1532
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1533
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1534
        fCurrentEntity.columnNumber += length;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1535
        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1536
7f561c08de6b Initial load
duke
parents:
diff changeset
  1537
    } // skipString(String):boolean
7f561c08de6b Initial load
duke
parents:
diff changeset
  1538
7f561c08de6b Initial load
duke
parents:
diff changeset
  1539
} // class XML11EntityScanner