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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 408
b0610cd08440
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25 /*
aoqi@0 26 * Copyright (C) 2004-2012
aoqi@0 27 *
aoqi@0 28 * Permission is hereby granted, free of charge, to any person obtaining a copy
aoqi@0 29 * of this software and associated documentation files (the "Software"), to deal
aoqi@0 30 * in the Software without restriction, including without limitation the rights
aoqi@0 31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
aoqi@0 32 * copies of the Software, and to permit persons to whom the Software is
aoqi@0 33 * furnished to do so, subject to the following conditions:
aoqi@0 34 *
aoqi@0 35 * The above copyright notice and this permission notice shall be included in
aoqi@0 36 * all copies or substantial portions of the Software.
aoqi@0 37 *
aoqi@0 38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
aoqi@0 39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
aoqi@0 40 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
aoqi@0 41 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
aoqi@0 42 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
aoqi@0 43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
aoqi@0 44 * THE SOFTWARE.
aoqi@0 45 */
aoqi@0 46 /* Generated By:JavaCC: Do not edit this line. UCode_UCodeESC_CharStream.java Version 0.7pre6 */
aoqi@0 47 /* The previous line keeps JavaCC quiet. In fact, the JavaCC generated file
aoqi@0 48 has been edited to fix some bugs. */
aoqi@0 49 package com.sun.xml.internal.rngom.parse.compact;
aoqi@0 50
aoqi@0 51 import com.sun.xml.internal.rngom.util.Utf16;
aoqi@0 52 import com.sun.xml.internal.rngom.ast.builder.BuildException;
aoqi@0 53
aoqi@0 54 import java.io.IOException;
aoqi@0 55
aoqi@0 56 /**
aoqi@0 57 * An implementation of interface CharStream, where the stream is assumed to
aoqi@0 58 * contain 16-bit unicode characters.
aoqi@0 59 */
aoqi@0 60 public final class UCode_UCodeESC_CharStream {
aoqi@0 61
aoqi@0 62 public static final boolean staticFlag = false;
aoqi@0 63
aoqi@0 64 static final int hexval(char c) {
aoqi@0 65 switch (c) {
aoqi@0 66 case '0':
aoqi@0 67 return 0;
aoqi@0 68 case '1':
aoqi@0 69 return 1;
aoqi@0 70 case '2':
aoqi@0 71 return 2;
aoqi@0 72 case '3':
aoqi@0 73 return 3;
aoqi@0 74 case '4':
aoqi@0 75 return 4;
aoqi@0 76 case '5':
aoqi@0 77 return 5;
aoqi@0 78 case '6':
aoqi@0 79 return 6;
aoqi@0 80 case '7':
aoqi@0 81 return 7;
aoqi@0 82 case '8':
aoqi@0 83 return 8;
aoqi@0 84 case '9':
aoqi@0 85 return 9;
aoqi@0 86
aoqi@0 87 case 'a':
aoqi@0 88 case 'A':
aoqi@0 89 return 10;
aoqi@0 90 case 'b':
aoqi@0 91 case 'B':
aoqi@0 92 return 11;
aoqi@0 93 case 'c':
aoqi@0 94 case 'C':
aoqi@0 95 return 12;
aoqi@0 96 case 'd':
aoqi@0 97 case 'D':
aoqi@0 98 return 13;
aoqi@0 99 case 'e':
aoqi@0 100 case 'E':
aoqi@0 101 return 14;
aoqi@0 102 case 'f':
aoqi@0 103 case 'F':
aoqi@0 104 return 15;
aoqi@0 105 }
aoqi@0 106 return -1;
aoqi@0 107 }
aoqi@0 108 public int bufpos = -1;
aoqi@0 109 int bufsize;
aoqi@0 110 int available;
aoqi@0 111 int tokenBegin;
aoqi@0 112 private int bufline[];
aoqi@0 113 private int bufcolumn[];
aoqi@0 114 private int column = 0;
aoqi@0 115 private int line = 1;
aoqi@0 116 private java.io.Reader inputStream;
aoqi@0 117 private boolean closed = false;
aoqi@0 118 private boolean prevCharIsLF = false;
aoqi@0 119 private char[] nextCharBuf;
aoqi@0 120 private char[] buffer;
aoqi@0 121 private int maxNextCharInd = 0;
aoqi@0 122 private int nextCharInd = -1;
aoqi@0 123 private int inBuf = 0;
aoqi@0 124
aoqi@0 125 private final void ExpandBuff(boolean wrapAround) {
aoqi@0 126 char[] newbuffer = new char[bufsize + 2048];
aoqi@0 127 int newbufline[] = new int[bufsize + 2048];
aoqi@0 128 int newbufcolumn[] = new int[bufsize + 2048];
aoqi@0 129
aoqi@0 130 if (wrapAround) {
aoqi@0 131 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
aoqi@0 132 System.arraycopy(buffer, 0, newbuffer,
aoqi@0 133 bufsize - tokenBegin, bufpos);
aoqi@0 134 buffer = newbuffer;
aoqi@0 135
aoqi@0 136 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
aoqi@0 137 System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
aoqi@0 138 bufline = newbufline;
aoqi@0 139
aoqi@0 140 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
aoqi@0 141 System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
aoqi@0 142 bufcolumn = newbufcolumn;
aoqi@0 143
aoqi@0 144 bufpos += (bufsize - tokenBegin);
aoqi@0 145 } else {
aoqi@0 146 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
aoqi@0 147 buffer = newbuffer;
aoqi@0 148
aoqi@0 149 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
aoqi@0 150 bufline = newbufline;
aoqi@0 151
aoqi@0 152 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
aoqi@0 153 bufcolumn = newbufcolumn;
aoqi@0 154
aoqi@0 155 bufpos -= tokenBegin;
aoqi@0 156 }
aoqi@0 157
aoqi@0 158 available = (bufsize += 2048);
aoqi@0 159 tokenBegin = 0;
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 private final void FillBuff() throws EOFException {
aoqi@0 163 int i;
aoqi@0 164 if (maxNextCharInd == 4096) {
aoqi@0 165 maxNextCharInd = nextCharInd = 0;
aoqi@0 166 }
aoqi@0 167
aoqi@0 168 if (closed) {
aoqi@0 169 throw new EOFException();
aoqi@0 170 }
aoqi@0 171 try {
aoqi@0 172 if ((i = inputStream.read(nextCharBuf, maxNextCharInd, 4096 - maxNextCharInd)) == -1) {
aoqi@0 173 closed = true;
aoqi@0 174 inputStream.close();
aoqi@0 175 throw new EOFException();
aoqi@0 176 } else {
aoqi@0 177 maxNextCharInd += i;
aoqi@0 178 }
aoqi@0 179 } catch (IOException e) {
aoqi@0 180 throw new BuildException(e);
aoqi@0 181 }
aoqi@0 182 }
aoqi@0 183
aoqi@0 184 private final char ReadChar() throws EOFException {
aoqi@0 185 if (++nextCharInd >= maxNextCharInd) {
aoqi@0 186 FillBuff();
aoqi@0 187 }
aoqi@0 188
aoqi@0 189 return nextCharBuf[nextCharInd];
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 private final char PeekChar() throws EOFException {
aoqi@0 193 char c = ReadChar();
aoqi@0 194 --nextCharInd;
aoqi@0 195 return c;
aoqi@0 196 }
aoqi@0 197
aoqi@0 198 public final char BeginToken() throws EOFException {
aoqi@0 199 if (inBuf > 0) {
aoqi@0 200 --inBuf;
aoqi@0 201 return buffer[tokenBegin = (bufpos == bufsize - 1) ? (bufpos = 0)
aoqi@0 202 : ++bufpos];
aoqi@0 203 }
aoqi@0 204
aoqi@0 205 tokenBegin = 0;
aoqi@0 206 bufpos = -1;
aoqi@0 207
aoqi@0 208 return readChar();
aoqi@0 209 }
aoqi@0 210
aoqi@0 211 private final void AdjustBuffSize() {
aoqi@0 212 if (available == bufsize) {
aoqi@0 213 if (tokenBegin > 2048) {
aoqi@0 214 bufpos = 0;
aoqi@0 215 available = tokenBegin;
aoqi@0 216 } else {
aoqi@0 217 ExpandBuff(false);
aoqi@0 218 }
aoqi@0 219 } else if (available > tokenBegin) {
aoqi@0 220 available = bufsize;
aoqi@0 221 } else if ((tokenBegin - available) < 2048) {
aoqi@0 222 ExpandBuff(true);
aoqi@0 223 } else {
aoqi@0 224 available = tokenBegin;
aoqi@0 225 }
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 private final void UpdateLineColumn(char c) {
aoqi@0 229 column++;
aoqi@0 230
aoqi@0 231 if (prevCharIsLF) {
aoqi@0 232 prevCharIsLF = false;
aoqi@0 233 line += (column = 1);
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 switch (c) {
aoqi@0 237 case NEWLINE_MARKER:
aoqi@0 238 prevCharIsLF = true;
aoqi@0 239 break;
aoqi@0 240 case '\t':
aoqi@0 241 column--;
aoqi@0 242 column += (8 - (column & 07));
aoqi@0 243 break;
aoqi@0 244 default:
aoqi@0 245 break;
aoqi@0 246 }
aoqi@0 247
aoqi@0 248 bufline[bufpos] = line;
aoqi@0 249 bufcolumn[bufpos] = column;
aoqi@0 250 }
aoqi@0 251 private static final char NEWLINE_MARKER = '\u0000';
aoqi@0 252
aoqi@0 253 public final char readChar() throws EOFException {
aoqi@0 254 if (inBuf > 0) {
aoqi@0 255 --inBuf;
aoqi@0 256 return buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos];
aoqi@0 257 }
aoqi@0 258
aoqi@0 259 char c;
aoqi@0 260 try {
aoqi@0 261 c = ReadChar();
aoqi@0 262 switch (c) {
aoqi@0 263 case '\r':
aoqi@0 264 c = NEWLINE_MARKER;
aoqi@0 265 try {
aoqi@0 266 if (PeekChar() == '\n') {
aoqi@0 267 ReadChar();
aoqi@0 268 }
aoqi@0 269 } catch (EOFException e) {
aoqi@0 270 }
aoqi@0 271 break;
aoqi@0 272 case '\n':
aoqi@0 273 c = NEWLINE_MARKER;
aoqi@0 274 break;
aoqi@0 275 case '\t':
aoqi@0 276 break;
aoqi@0 277 default:
aoqi@0 278 if (c >= 0x20) {
aoqi@0 279 if (Utf16.isSurrogate(c)) {
aoqi@0 280 if (Utf16.isSurrogate2(c)) {
aoqi@0 281 throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 1);
aoqi@0 282 }
aoqi@0 283 if (++bufpos == available) {
aoqi@0 284 AdjustBuffSize();
aoqi@0 285 }
aoqi@0 286 buffer[bufpos] = c;
aoqi@0 287 // UpdateLineColumn(c);
aoqi@0 288 try {
aoqi@0 289 c = ReadChar();
aoqi@0 290 } catch (EOFException e) {
aoqi@0 291 throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 1);
aoqi@0 292 }
aoqi@0 293 if (!Utf16.isSurrogate2(c)) {
aoqi@0 294 throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 2);
aoqi@0 295 }
aoqi@0 296 }
aoqi@0 297 break;
aoqi@0 298 }
aoqi@0 299 // fall through
aoqi@0 300 case '\uFFFE':
aoqi@0 301 case '\uFFFF':
aoqi@0 302 throw new EscapeSyntaxException("illegal_char_code", line, column + 1);
aoqi@0 303 }
aoqi@0 304 } catch (EOFException e) {
aoqi@0 305 if (bufpos == -1) {
aoqi@0 306 if (++bufpos == available) {
aoqi@0 307 AdjustBuffSize();
aoqi@0 308 }
aoqi@0 309 bufline[bufpos] = line;
aoqi@0 310 bufcolumn[bufpos] = column;
aoqi@0 311 }
aoqi@0 312 throw e;
aoqi@0 313 }
aoqi@0 314 if (++bufpos == available) {
aoqi@0 315 AdjustBuffSize();
aoqi@0 316 }
aoqi@0 317 buffer[bufpos] = c;
aoqi@0 318 UpdateLineColumn(c);
aoqi@0 319 try {
aoqi@0 320 if (c != '\\' || PeekChar() != 'x') {
aoqi@0 321 return c;
aoqi@0 322 }
aoqi@0 323 } catch (EOFException e) {
aoqi@0 324 return c;
aoqi@0 325 }
aoqi@0 326
aoqi@0 327 int xCnt = 1;
aoqi@0 328 for (;;) {
aoqi@0 329 ReadChar();
aoqi@0 330 if (++bufpos == available) {
aoqi@0 331 AdjustBuffSize();
aoqi@0 332 }
aoqi@0 333 buffer[bufpos] = 'x';
aoqi@0 334 UpdateLineColumn('x');
aoqi@0 335 try {
aoqi@0 336 c = PeekChar();
aoqi@0 337 } catch (EOFException e) {
aoqi@0 338 backup(xCnt);
aoqi@0 339 return '\\';
aoqi@0 340 }
aoqi@0 341 if (c == '{') {
aoqi@0 342 ReadChar();
aoqi@0 343 column++;
aoqi@0 344 // backup past the 'x's
aoqi@0 345 bufpos -= xCnt;
aoqi@0 346 if (bufpos < 0) {
aoqi@0 347 bufpos += bufsize;
aoqi@0 348 }
aoqi@0 349 break;
aoqi@0 350 }
aoqi@0 351 if (c != 'x') {
aoqi@0 352 backup(xCnt);
aoqi@0 353 return '\\';
aoqi@0 354 }
aoqi@0 355 xCnt++;
aoqi@0 356 }
aoqi@0 357 try {
aoqi@0 358 int scalarValue = hexval(ReadChar());
aoqi@0 359 column++;
aoqi@0 360 if (scalarValue < 0) {
aoqi@0 361 throw new EscapeSyntaxException("illegal_hex_digit", line, column);
aoqi@0 362 }
aoqi@0 363 while ((c = ReadChar()) != '}') {
aoqi@0 364 column++;
aoqi@0 365 int n = hexval(c);
aoqi@0 366 if (n < 0) {
aoqi@0 367 throw new EscapeSyntaxException("illegal_hex_digit", line, column);
aoqi@0 368 }
aoqi@0 369 scalarValue <<= 4;
aoqi@0 370 scalarValue |= n;
aoqi@0 371 if (scalarValue >= 0x110000) {
aoqi@0 372 throw new EscapeSyntaxException("char_code_too_big", line, column);
aoqi@0 373 }
aoqi@0 374 }
aoqi@0 375 column++; // for the '}'
aoqi@0 376 if (scalarValue <= 0xFFFF) {
aoqi@0 377 c = (char) scalarValue;
aoqi@0 378 switch (c) {
aoqi@0 379 case '\n':
aoqi@0 380 case '\r':
aoqi@0 381 case '\t':
aoqi@0 382 break;
aoqi@0 383 default:
aoqi@0 384 if (c >= 0x20 && !Utf16.isSurrogate(c)) {
aoqi@0 385 break;
aoqi@0 386 }
aoqi@0 387 // fall through
aoqi@0 388 case '\uFFFE':
aoqi@0 389 case '\uFFFF':
aoqi@0 390 throw new EscapeSyntaxException("illegal_char_code_ref", line, column);
aoqi@0 391 }
aoqi@0 392 buffer[bufpos] = c;
aoqi@0 393 return c;
aoqi@0 394 }
aoqi@0 395 c = Utf16.surrogate1(scalarValue);
aoqi@0 396 buffer[bufpos] = c;
aoqi@0 397 int bufpos1 = bufpos;
aoqi@0 398 if (++bufpos == bufsize) {
aoqi@0 399 bufpos = 0;
aoqi@0 400 }
aoqi@0 401 buffer[bufpos] = Utf16.surrogate2(scalarValue);
aoqi@0 402 bufline[bufpos] = bufline[bufpos1];
aoqi@0 403 bufcolumn[bufpos] = bufcolumn[bufpos1];
aoqi@0 404 backup(1);
aoqi@0 405 return c;
aoqi@0 406 } catch (EOFException e) {
aoqi@0 407 throw new EscapeSyntaxException("incomplete_escape", line, column);
aoqi@0 408 }
aoqi@0 409 }
aoqi@0 410
aoqi@0 411 /**
aoqi@0 412 * @deprecated @see #getEndColumn
aoqi@0 413 */
aoqi@0 414 public final int getColumn() {
aoqi@0 415 return bufcolumn[bufpos];
aoqi@0 416 }
aoqi@0 417
aoqi@0 418 /**
aoqi@0 419 * @deprecated @see #getEndLine
aoqi@0 420 */
aoqi@0 421 public final int getLine() {
aoqi@0 422 return bufline[bufpos];
aoqi@0 423 }
aoqi@0 424
aoqi@0 425 public final int getEndColumn() {
aoqi@0 426 return bufcolumn[bufpos];
aoqi@0 427 }
aoqi@0 428
aoqi@0 429 public final int getEndLine() {
aoqi@0 430 return bufline[bufpos];
aoqi@0 431 }
aoqi@0 432
aoqi@0 433 public final int getBeginColumn() {
aoqi@0 434 return bufcolumn[tokenBegin];
aoqi@0 435 }
aoqi@0 436
aoqi@0 437 public final int getBeginLine() {
aoqi@0 438 return bufline[tokenBegin];
aoqi@0 439 }
aoqi@0 440
aoqi@0 441 public final void backup(int amount) {
aoqi@0 442
aoqi@0 443 inBuf += amount;
aoqi@0 444 if ((bufpos -= amount) < 0) {
aoqi@0 445 bufpos += bufsize;
aoqi@0 446 }
aoqi@0 447 }
aoqi@0 448
aoqi@0 449 public UCode_UCodeESC_CharStream(java.io.Reader dstream,
aoqi@0 450 int startline, int startcolumn, int buffersize) {
aoqi@0 451 inputStream = dstream;
aoqi@0 452 line = startline;
aoqi@0 453 column = startcolumn - 1;
aoqi@0 454
aoqi@0 455 available = bufsize = buffersize;
aoqi@0 456 buffer = new char[buffersize];
aoqi@0 457 bufline = new int[buffersize];
aoqi@0 458 bufcolumn = new int[buffersize];
aoqi@0 459 nextCharBuf = new char[4096];
aoqi@0 460 skipBOM();
aoqi@0 461 }
aoqi@0 462
aoqi@0 463 public UCode_UCodeESC_CharStream(java.io.Reader dstream,
aoqi@0 464 int startline, int startcolumn) {
aoqi@0 465 this(dstream, startline, startcolumn, 4096);
aoqi@0 466 }
aoqi@0 467
aoqi@0 468 public void ReInit(java.io.Reader dstream,
aoqi@0 469 int startline, int startcolumn, int buffersize) {
aoqi@0 470 inputStream = dstream;
aoqi@0 471 closed = false;
aoqi@0 472 line = startline;
aoqi@0 473 column = startcolumn - 1;
aoqi@0 474
aoqi@0 475 if (buffer == null || buffersize != buffer.length) {
aoqi@0 476 available = bufsize = buffersize;
aoqi@0 477 buffer = new char[buffersize];
aoqi@0 478 bufline = new int[buffersize];
aoqi@0 479 bufcolumn = new int[buffersize];
aoqi@0 480 nextCharBuf = new char[4096];
aoqi@0 481 }
aoqi@0 482 prevCharIsLF = false;
aoqi@0 483 tokenBegin = inBuf = maxNextCharInd = 0;
aoqi@0 484 nextCharInd = bufpos = -1;
aoqi@0 485 skipBOM();
aoqi@0 486 }
aoqi@0 487
aoqi@0 488 public void ReInit(java.io.Reader dstream,
aoqi@0 489 int startline, int startcolumn) {
aoqi@0 490 ReInit(dstream, startline, startcolumn, 4096);
aoqi@0 491 }
aoqi@0 492
aoqi@0 493 public UCode_UCodeESC_CharStream(java.io.InputStream dstream, int startline,
aoqi@0 494 int startcolumn, int buffersize) {
aoqi@0 495 this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
aoqi@0 496 }
aoqi@0 497
aoqi@0 498 public UCode_UCodeESC_CharStream(java.io.InputStream dstream, int startline,
aoqi@0 499 int startcolumn) {
aoqi@0 500 this(dstream, startline, startcolumn, 4096);
aoqi@0 501 }
aoqi@0 502
aoqi@0 503 public void ReInit(java.io.InputStream dstream, int startline,
aoqi@0 504 int startcolumn, int buffersize) {
aoqi@0 505 ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
aoqi@0 506 }
aoqi@0 507
aoqi@0 508 public void ReInit(java.io.InputStream dstream, int startline,
aoqi@0 509 int startcolumn) {
aoqi@0 510 ReInit(dstream, startline, startcolumn, 4096);
aoqi@0 511 }
aoqi@0 512 static private final char BOM = '\ufeff';
aoqi@0 513
aoqi@0 514 private void skipBOM() {
aoqi@0 515 try {
aoqi@0 516 if (PeekChar() == BOM) {
aoqi@0 517 ReadChar();
aoqi@0 518 }
aoqi@0 519 } catch (EOFException e) {
aoqi@0 520 }
aoqi@0 521 }
aoqi@0 522
aoqi@0 523 public final String GetImage() {
aoqi@0 524 if (bufpos >= tokenBegin) {
aoqi@0 525 return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
aoqi@0 526 } else {
aoqi@0 527 return new String(buffer, tokenBegin, bufsize - tokenBegin)
aoqi@0 528 + new String(buffer, 0, bufpos + 1);
aoqi@0 529 }
aoqi@0 530 }
aoqi@0 531
aoqi@0 532 public final char[] GetSuffix(int len) {
aoqi@0 533 char[] ret = new char[len];
aoqi@0 534
aoqi@0 535 if ((bufpos + 1) >= len) {
aoqi@0 536 System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
aoqi@0 537 } else {
aoqi@0 538 System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
aoqi@0 539 len - bufpos - 1);
aoqi@0 540 System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
aoqi@0 541 }
aoqi@0 542
aoqi@0 543 return ret;
aoqi@0 544 }
aoqi@0 545
aoqi@0 546 public void Done() {
aoqi@0 547 nextCharBuf = null;
aoqi@0 548 buffer = null;
aoqi@0 549 bufline = null;
aoqi@0 550 bufcolumn = null;
aoqi@0 551 }
aoqi@0 552
aoqi@0 553 /**
aoqi@0 554 * Method to adjust line and column numbers for the start of a token.<BR>
aoqi@0 555 */
aoqi@0 556 public void adjustBeginLineColumn(int newLine, int newCol) {
aoqi@0 557 int start = tokenBegin;
aoqi@0 558 int len;
aoqi@0 559
aoqi@0 560 if (bufpos >= tokenBegin) {
aoqi@0 561 len = bufpos - tokenBegin + inBuf + 1;
aoqi@0 562 } else {
aoqi@0 563 len = bufsize - tokenBegin + bufpos + 1 + inBuf;
aoqi@0 564 }
aoqi@0 565
aoqi@0 566 int i = 0, j = 0, k = 0;
aoqi@0 567 int nextColDiff, columnDiff = 0;
aoqi@0 568
aoqi@0 569 while (i < len
aoqi@0 570 && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) {
aoqi@0 571 bufline[j] = newLine;
aoqi@0 572 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
aoqi@0 573 bufcolumn[j] = newCol + columnDiff;
aoqi@0 574 columnDiff = nextColDiff;
aoqi@0 575 i++;
aoqi@0 576 }
aoqi@0 577
aoqi@0 578 if (i < len) {
aoqi@0 579 bufline[j] = newLine++;
aoqi@0 580 bufcolumn[j] = newCol + columnDiff;
aoqi@0 581
aoqi@0 582 while (i++ < len) {
aoqi@0 583 if (bufline[j = start % bufsize] != bufline[++start % bufsize]) {
aoqi@0 584 bufline[j] = newLine++;
aoqi@0 585 } else {
aoqi@0 586 bufline[j] = newLine;
aoqi@0 587 }
aoqi@0 588 }
aoqi@0 589 }
aoqi@0 590
aoqi@0 591 line = bufline[j];
aoqi@0 592 column = bufcolumn[j];
aoqi@0 593 }
aoqi@0 594 }

mercurial