src/share/jaxws_classes/com/sun/xml/internal/rngom/parse/compact/UCode_UCodeESC_CharStream.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/rngom/parse/compact/UCode_UCodeESC_CharStream.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,594 @@
     1.4 +/*
     1.5 + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +/*
    1.29 + * Copyright (C) 2004-2012
    1.30 + *
    1.31 + * Permission is hereby granted, free of charge, to any person obtaining a copy
    1.32 + * of this software and associated documentation files (the "Software"), to deal
    1.33 + * in the Software without restriction, including without limitation the rights
    1.34 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    1.35 + * copies of the Software, and to permit persons to whom the Software is
    1.36 + * furnished to do so, subject to the following conditions:
    1.37 + *
    1.38 + * The above copyright notice and this permission notice shall be included in
    1.39 + * all copies or substantial portions of the Software.
    1.40 + *
    1.41 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1.42 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1.43 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    1.44 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    1.45 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    1.46 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    1.47 + * THE SOFTWARE.
    1.48 + */
    1.49 +/* Generated By:JavaCC: Do not edit this line. UCode_UCodeESC_CharStream.java Version 0.7pre6 */
    1.50 +/* The previous line keeps JavaCC quiet. In fact, the JavaCC generated file
    1.51 + has been edited to fix some bugs. */
    1.52 +package com.sun.xml.internal.rngom.parse.compact;
    1.53 +
    1.54 +import com.sun.xml.internal.rngom.util.Utf16;
    1.55 +import com.sun.xml.internal.rngom.ast.builder.BuildException;
    1.56 +
    1.57 +import java.io.IOException;
    1.58 +
    1.59 +/**
    1.60 + * An implementation of interface CharStream, where the stream is assumed to
    1.61 + * contain 16-bit unicode characters.
    1.62 + */
    1.63 +public final class UCode_UCodeESC_CharStream {
    1.64 +
    1.65 +    public static final boolean staticFlag = false;
    1.66 +
    1.67 +    static final int hexval(char c) {
    1.68 +        switch (c) {
    1.69 +            case '0':
    1.70 +                return 0;
    1.71 +            case '1':
    1.72 +                return 1;
    1.73 +            case '2':
    1.74 +                return 2;
    1.75 +            case '3':
    1.76 +                return 3;
    1.77 +            case '4':
    1.78 +                return 4;
    1.79 +            case '5':
    1.80 +                return 5;
    1.81 +            case '6':
    1.82 +                return 6;
    1.83 +            case '7':
    1.84 +                return 7;
    1.85 +            case '8':
    1.86 +                return 8;
    1.87 +            case '9':
    1.88 +                return 9;
    1.89 +
    1.90 +            case 'a':
    1.91 +            case 'A':
    1.92 +                return 10;
    1.93 +            case 'b':
    1.94 +            case 'B':
    1.95 +                return 11;
    1.96 +            case 'c':
    1.97 +            case 'C':
    1.98 +                return 12;
    1.99 +            case 'd':
   1.100 +            case 'D':
   1.101 +                return 13;
   1.102 +            case 'e':
   1.103 +            case 'E':
   1.104 +                return 14;
   1.105 +            case 'f':
   1.106 +            case 'F':
   1.107 +                return 15;
   1.108 +        }
   1.109 +        return -1;
   1.110 +    }
   1.111 +    public int bufpos = -1;
   1.112 +    int bufsize;
   1.113 +    int available;
   1.114 +    int tokenBegin;
   1.115 +    private int bufline[];
   1.116 +    private int bufcolumn[];
   1.117 +    private int column = 0;
   1.118 +    private int line = 1;
   1.119 +    private java.io.Reader inputStream;
   1.120 +    private boolean closed = false;
   1.121 +    private boolean prevCharIsLF = false;
   1.122 +    private char[] nextCharBuf;
   1.123 +    private char[] buffer;
   1.124 +    private int maxNextCharInd = 0;
   1.125 +    private int nextCharInd = -1;
   1.126 +    private int inBuf = 0;
   1.127 +
   1.128 +    private final void ExpandBuff(boolean wrapAround) {
   1.129 +        char[] newbuffer = new char[bufsize + 2048];
   1.130 +        int newbufline[] = new int[bufsize + 2048];
   1.131 +        int newbufcolumn[] = new int[bufsize + 2048];
   1.132 +
   1.133 +        if (wrapAround) {
   1.134 +            System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
   1.135 +            System.arraycopy(buffer, 0, newbuffer,
   1.136 +                    bufsize - tokenBegin, bufpos);
   1.137 +            buffer = newbuffer;
   1.138 +
   1.139 +            System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
   1.140 +            System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
   1.141 +            bufline = newbufline;
   1.142 +
   1.143 +            System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
   1.144 +            System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
   1.145 +            bufcolumn = newbufcolumn;
   1.146 +
   1.147 +            bufpos += (bufsize - tokenBegin);
   1.148 +        } else {
   1.149 +            System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
   1.150 +            buffer = newbuffer;
   1.151 +
   1.152 +            System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
   1.153 +            bufline = newbufline;
   1.154 +
   1.155 +            System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
   1.156 +            bufcolumn = newbufcolumn;
   1.157 +
   1.158 +            bufpos -= tokenBegin;
   1.159 +        }
   1.160 +
   1.161 +        available = (bufsize += 2048);
   1.162 +        tokenBegin = 0;
   1.163 +    }
   1.164 +
   1.165 +    private final void FillBuff() throws EOFException {
   1.166 +        int i;
   1.167 +        if (maxNextCharInd == 4096) {
   1.168 +            maxNextCharInd = nextCharInd = 0;
   1.169 +        }
   1.170 +
   1.171 +        if (closed) {
   1.172 +            throw new EOFException();
   1.173 +        }
   1.174 +        try {
   1.175 +            if ((i = inputStream.read(nextCharBuf, maxNextCharInd, 4096 - maxNextCharInd)) == -1) {
   1.176 +                closed = true;
   1.177 +                inputStream.close();
   1.178 +                throw new EOFException();
   1.179 +            } else {
   1.180 +                maxNextCharInd += i;
   1.181 +            }
   1.182 +        } catch (IOException e) {
   1.183 +            throw new BuildException(e);
   1.184 +        }
   1.185 +    }
   1.186 +
   1.187 +    private final char ReadChar() throws EOFException {
   1.188 +        if (++nextCharInd >= maxNextCharInd) {
   1.189 +            FillBuff();
   1.190 +        }
   1.191 +
   1.192 +        return nextCharBuf[nextCharInd];
   1.193 +    }
   1.194 +
   1.195 +    private final char PeekChar() throws EOFException {
   1.196 +        char c = ReadChar();
   1.197 +        --nextCharInd;
   1.198 +        return c;
   1.199 +    }
   1.200 +
   1.201 +    public final char BeginToken() throws EOFException {
   1.202 +        if (inBuf > 0) {
   1.203 +            --inBuf;
   1.204 +            return buffer[tokenBegin = (bufpos == bufsize - 1) ? (bufpos = 0)
   1.205 +                    : ++bufpos];
   1.206 +        }
   1.207 +
   1.208 +        tokenBegin = 0;
   1.209 +        bufpos = -1;
   1.210 +
   1.211 +        return readChar();
   1.212 +    }
   1.213 +
   1.214 +    private final void AdjustBuffSize() {
   1.215 +        if (available == bufsize) {
   1.216 +            if (tokenBegin > 2048) {
   1.217 +                bufpos = 0;
   1.218 +                available = tokenBegin;
   1.219 +            } else {
   1.220 +                ExpandBuff(false);
   1.221 +            }
   1.222 +        } else if (available > tokenBegin) {
   1.223 +            available = bufsize;
   1.224 +        } else if ((tokenBegin - available) < 2048) {
   1.225 +            ExpandBuff(true);
   1.226 +        } else {
   1.227 +            available = tokenBegin;
   1.228 +        }
   1.229 +    }
   1.230 +
   1.231 +    private final void UpdateLineColumn(char c) {
   1.232 +        column++;
   1.233 +
   1.234 +        if (prevCharIsLF) {
   1.235 +            prevCharIsLF = false;
   1.236 +            line += (column = 1);
   1.237 +        }
   1.238 +
   1.239 +        switch (c) {
   1.240 +            case NEWLINE_MARKER:
   1.241 +                prevCharIsLF = true;
   1.242 +                break;
   1.243 +            case '\t':
   1.244 +                column--;
   1.245 +                column += (8 - (column & 07));
   1.246 +                break;
   1.247 +            default:
   1.248 +                break;
   1.249 +        }
   1.250 +
   1.251 +        bufline[bufpos] = line;
   1.252 +        bufcolumn[bufpos] = column;
   1.253 +    }
   1.254 +    private static final char NEWLINE_MARKER = '\u0000';
   1.255 +
   1.256 +    public final char readChar() throws EOFException {
   1.257 +        if (inBuf > 0) {
   1.258 +            --inBuf;
   1.259 +            return buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos];
   1.260 +        }
   1.261 +
   1.262 +        char c;
   1.263 +        try {
   1.264 +            c = ReadChar();
   1.265 +            switch (c) {
   1.266 +                case '\r':
   1.267 +                    c = NEWLINE_MARKER;
   1.268 +                    try {
   1.269 +                        if (PeekChar() == '\n') {
   1.270 +                            ReadChar();
   1.271 +                        }
   1.272 +                    } catch (EOFException e) {
   1.273 +                    }
   1.274 +                    break;
   1.275 +                case '\n':
   1.276 +                    c = NEWLINE_MARKER;
   1.277 +                    break;
   1.278 +                case '\t':
   1.279 +                    break;
   1.280 +                default:
   1.281 +                    if (c >= 0x20) {
   1.282 +                        if (Utf16.isSurrogate(c)) {
   1.283 +                            if (Utf16.isSurrogate2(c)) {
   1.284 +                                throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 1);
   1.285 +                            }
   1.286 +                            if (++bufpos == available) {
   1.287 +                                AdjustBuffSize();
   1.288 +                            }
   1.289 +                            buffer[bufpos] = c;
   1.290 +                            // UpdateLineColumn(c);
   1.291 +                            try {
   1.292 +                                c = ReadChar();
   1.293 +                            } catch (EOFException e) {
   1.294 +                                throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 1);
   1.295 +                            }
   1.296 +                            if (!Utf16.isSurrogate2(c)) {
   1.297 +                                throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 2);
   1.298 +                            }
   1.299 +                        }
   1.300 +                        break;
   1.301 +                    }
   1.302 +                // fall through
   1.303 +                case '\uFFFE':
   1.304 +                case '\uFFFF':
   1.305 +                    throw new EscapeSyntaxException("illegal_char_code", line, column + 1);
   1.306 +            }
   1.307 +        } catch (EOFException e) {
   1.308 +            if (bufpos == -1) {
   1.309 +                if (++bufpos == available) {
   1.310 +                    AdjustBuffSize();
   1.311 +                }
   1.312 +                bufline[bufpos] = line;
   1.313 +                bufcolumn[bufpos] = column;
   1.314 +            }
   1.315 +            throw e;
   1.316 +        }
   1.317 +        if (++bufpos == available) {
   1.318 +            AdjustBuffSize();
   1.319 +        }
   1.320 +        buffer[bufpos] = c;
   1.321 +        UpdateLineColumn(c);
   1.322 +        try {
   1.323 +            if (c != '\\' || PeekChar() != 'x') {
   1.324 +                return c;
   1.325 +            }
   1.326 +        } catch (EOFException e) {
   1.327 +            return c;
   1.328 +        }
   1.329 +
   1.330 +        int xCnt = 1;
   1.331 +        for (;;) {
   1.332 +            ReadChar();
   1.333 +            if (++bufpos == available) {
   1.334 +                AdjustBuffSize();
   1.335 +            }
   1.336 +            buffer[bufpos] = 'x';
   1.337 +            UpdateLineColumn('x');
   1.338 +            try {
   1.339 +                c = PeekChar();
   1.340 +            } catch (EOFException e) {
   1.341 +                backup(xCnt);
   1.342 +                return '\\';
   1.343 +            }
   1.344 +            if (c == '{') {
   1.345 +                ReadChar();
   1.346 +                column++;
   1.347 +                // backup past the 'x's
   1.348 +                bufpos -= xCnt;
   1.349 +                if (bufpos < 0) {
   1.350 +                    bufpos += bufsize;
   1.351 +                }
   1.352 +                break;
   1.353 +            }
   1.354 +            if (c != 'x') {
   1.355 +                backup(xCnt);
   1.356 +                return '\\';
   1.357 +            }
   1.358 +            xCnt++;
   1.359 +        }
   1.360 +        try {
   1.361 +            int scalarValue = hexval(ReadChar());
   1.362 +            column++;
   1.363 +            if (scalarValue < 0) {
   1.364 +                throw new EscapeSyntaxException("illegal_hex_digit", line, column);
   1.365 +            }
   1.366 +            while ((c = ReadChar()) != '}') {
   1.367 +                column++;
   1.368 +                int n = hexval(c);
   1.369 +                if (n < 0) {
   1.370 +                    throw new EscapeSyntaxException("illegal_hex_digit", line, column);
   1.371 +                }
   1.372 +                scalarValue <<= 4;
   1.373 +                scalarValue |= n;
   1.374 +                if (scalarValue >= 0x110000) {
   1.375 +                    throw new EscapeSyntaxException("char_code_too_big", line, column);
   1.376 +                }
   1.377 +            }
   1.378 +            column++; // for the '}'
   1.379 +            if (scalarValue <= 0xFFFF) {
   1.380 +                c = (char) scalarValue;
   1.381 +                switch (c) {
   1.382 +                    case '\n':
   1.383 +                    case '\r':
   1.384 +                    case '\t':
   1.385 +                        break;
   1.386 +                    default:
   1.387 +                        if (c >= 0x20 && !Utf16.isSurrogate(c)) {
   1.388 +                            break;
   1.389 +                        }
   1.390 +                    // fall through
   1.391 +                    case '\uFFFE':
   1.392 +                    case '\uFFFF':
   1.393 +                        throw new EscapeSyntaxException("illegal_char_code_ref", line, column);
   1.394 +                }
   1.395 +                buffer[bufpos] = c;
   1.396 +                return c;
   1.397 +            }
   1.398 +            c = Utf16.surrogate1(scalarValue);
   1.399 +            buffer[bufpos] = c;
   1.400 +            int bufpos1 = bufpos;
   1.401 +            if (++bufpos == bufsize) {
   1.402 +                bufpos = 0;
   1.403 +            }
   1.404 +            buffer[bufpos] = Utf16.surrogate2(scalarValue);
   1.405 +            bufline[bufpos] = bufline[bufpos1];
   1.406 +            bufcolumn[bufpos] = bufcolumn[bufpos1];
   1.407 +            backup(1);
   1.408 +            return c;
   1.409 +        } catch (EOFException e) {
   1.410 +            throw new EscapeSyntaxException("incomplete_escape", line, column);
   1.411 +        }
   1.412 +    }
   1.413 +
   1.414 +    /**
   1.415 +     * @deprecated @see #getEndColumn
   1.416 +     */
   1.417 +    public final int getColumn() {
   1.418 +        return bufcolumn[bufpos];
   1.419 +    }
   1.420 +
   1.421 +    /**
   1.422 +     * @deprecated @see #getEndLine
   1.423 +     */
   1.424 +    public final int getLine() {
   1.425 +        return bufline[bufpos];
   1.426 +    }
   1.427 +
   1.428 +    public final int getEndColumn() {
   1.429 +        return bufcolumn[bufpos];
   1.430 +    }
   1.431 +
   1.432 +    public final int getEndLine() {
   1.433 +        return bufline[bufpos];
   1.434 +    }
   1.435 +
   1.436 +    public final int getBeginColumn() {
   1.437 +        return bufcolumn[tokenBegin];
   1.438 +    }
   1.439 +
   1.440 +    public final int getBeginLine() {
   1.441 +        return bufline[tokenBegin];
   1.442 +    }
   1.443 +
   1.444 +    public final void backup(int amount) {
   1.445 +
   1.446 +        inBuf += amount;
   1.447 +        if ((bufpos -= amount) < 0) {
   1.448 +            bufpos += bufsize;
   1.449 +        }
   1.450 +    }
   1.451 +
   1.452 +    public UCode_UCodeESC_CharStream(java.io.Reader dstream,
   1.453 +            int startline, int startcolumn, int buffersize) {
   1.454 +        inputStream = dstream;
   1.455 +        line = startline;
   1.456 +        column = startcolumn - 1;
   1.457 +
   1.458 +        available = bufsize = buffersize;
   1.459 +        buffer = new char[buffersize];
   1.460 +        bufline = new int[buffersize];
   1.461 +        bufcolumn = new int[buffersize];
   1.462 +        nextCharBuf = new char[4096];
   1.463 +        skipBOM();
   1.464 +    }
   1.465 +
   1.466 +    public UCode_UCodeESC_CharStream(java.io.Reader dstream,
   1.467 +            int startline, int startcolumn) {
   1.468 +        this(dstream, startline, startcolumn, 4096);
   1.469 +    }
   1.470 +
   1.471 +    public void ReInit(java.io.Reader dstream,
   1.472 +            int startline, int startcolumn, int buffersize) {
   1.473 +        inputStream = dstream;
   1.474 +        closed = false;
   1.475 +        line = startline;
   1.476 +        column = startcolumn - 1;
   1.477 +
   1.478 +        if (buffer == null || buffersize != buffer.length) {
   1.479 +            available = bufsize = buffersize;
   1.480 +            buffer = new char[buffersize];
   1.481 +            bufline = new int[buffersize];
   1.482 +            bufcolumn = new int[buffersize];
   1.483 +            nextCharBuf = new char[4096];
   1.484 +        }
   1.485 +        prevCharIsLF = false;
   1.486 +        tokenBegin = inBuf = maxNextCharInd = 0;
   1.487 +        nextCharInd = bufpos = -1;
   1.488 +        skipBOM();
   1.489 +    }
   1.490 +
   1.491 +    public void ReInit(java.io.Reader dstream,
   1.492 +            int startline, int startcolumn) {
   1.493 +        ReInit(dstream, startline, startcolumn, 4096);
   1.494 +    }
   1.495 +
   1.496 +    public UCode_UCodeESC_CharStream(java.io.InputStream dstream, int startline,
   1.497 +            int startcolumn, int buffersize) {
   1.498 +        this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
   1.499 +    }
   1.500 +
   1.501 +    public UCode_UCodeESC_CharStream(java.io.InputStream dstream, int startline,
   1.502 +            int startcolumn) {
   1.503 +        this(dstream, startline, startcolumn, 4096);
   1.504 +    }
   1.505 +
   1.506 +    public void ReInit(java.io.InputStream dstream, int startline,
   1.507 +            int startcolumn, int buffersize) {
   1.508 +        ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
   1.509 +    }
   1.510 +
   1.511 +    public void ReInit(java.io.InputStream dstream, int startline,
   1.512 +            int startcolumn) {
   1.513 +        ReInit(dstream, startline, startcolumn, 4096);
   1.514 +    }
   1.515 +    static private final char BOM = '\ufeff';
   1.516 +
   1.517 +    private void skipBOM() {
   1.518 +        try {
   1.519 +            if (PeekChar() == BOM) {
   1.520 +                ReadChar();
   1.521 +            }
   1.522 +        } catch (EOFException e) {
   1.523 +        }
   1.524 +    }
   1.525 +
   1.526 +    public final String GetImage() {
   1.527 +        if (bufpos >= tokenBegin) {
   1.528 +            return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
   1.529 +        } else {
   1.530 +            return new String(buffer, tokenBegin, bufsize - tokenBegin)
   1.531 +                    + new String(buffer, 0, bufpos + 1);
   1.532 +        }
   1.533 +    }
   1.534 +
   1.535 +    public final char[] GetSuffix(int len) {
   1.536 +        char[] ret = new char[len];
   1.537 +
   1.538 +        if ((bufpos + 1) >= len) {
   1.539 +            System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
   1.540 +        } else {
   1.541 +            System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
   1.542 +                    len - bufpos - 1);
   1.543 +            System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
   1.544 +        }
   1.545 +
   1.546 +        return ret;
   1.547 +    }
   1.548 +
   1.549 +    public void Done() {
   1.550 +        nextCharBuf = null;
   1.551 +        buffer = null;
   1.552 +        bufline = null;
   1.553 +        bufcolumn = null;
   1.554 +    }
   1.555 +
   1.556 +    /**
   1.557 +     * Method to adjust line and column numbers for the start of a token.<BR>
   1.558 +     */
   1.559 +    public void adjustBeginLineColumn(int newLine, int newCol) {
   1.560 +        int start = tokenBegin;
   1.561 +        int len;
   1.562 +
   1.563 +        if (bufpos >= tokenBegin) {
   1.564 +            len = bufpos - tokenBegin + inBuf + 1;
   1.565 +        } else {
   1.566 +            len = bufsize - tokenBegin + bufpos + 1 + inBuf;
   1.567 +        }
   1.568 +
   1.569 +        int i = 0, j = 0, k = 0;
   1.570 +        int nextColDiff, columnDiff = 0;
   1.571 +
   1.572 +        while (i < len
   1.573 +                && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) {
   1.574 +            bufline[j] = newLine;
   1.575 +            nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
   1.576 +            bufcolumn[j] = newCol + columnDiff;
   1.577 +            columnDiff = nextColDiff;
   1.578 +            i++;
   1.579 +        }
   1.580 +
   1.581 +        if (i < len) {
   1.582 +            bufline[j] = newLine++;
   1.583 +            bufcolumn[j] = newCol + columnDiff;
   1.584 +
   1.585 +            while (i++ < len) {
   1.586 +                if (bufline[j = start % bufsize] != bufline[++start % bufsize]) {
   1.587 +                    bufline[j] = newLine++;
   1.588 +                } else {
   1.589 +                    bufline[j] = newLine;
   1.590 +                }
   1.591 +            }
   1.592 +        }
   1.593 +
   1.594 +        line = bufline[j];
   1.595 +        column = bufcolumn[j];
   1.596 +    }
   1.597 +}

mercurial