2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 /* Please see the following wiki for details of this functionality:
19 * http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782
22 package com.mysql.clusterj.jdbc.antlr;
25 import java.io.FileInputStream;
26 import java.io.IOException;
27 import java.io.InputStreamReader;
29 import org.antlr.runtime.ANTLRStringStream;
30 import org.antlr.runtime.CharStream;
32 public class ANTLRNoCaseStringStream extends ANTLRStringStream {
34 transient private String fileName;
36 public ANTLRNoCaseStringStream() {
40 public ANTLRNoCaseStringStream(final String string) {
44 public ANTLRNoCaseStringStream(final File file) throws IOException {
48 public ANTLRNoCaseStringStream(final File file, final String encoding)
50 this.fileName = file.getName();
55 public int LA(final int i) {
58 return 0; // undefined
62 if ((p + idx - 1) < 0) {
63 return CharStream.EOF; // invalid; no char before first char
67 if ((p + idx - 1) >= n) {
68 return CharStream.EOF;
70 return Character.toUpperCase(data[p + idx - 1]);
74 * For use in semantic predicates that need to access the actual case of a
75 * character for correct tokenization.
78 * Amount of lookahead characters
79 * @return the character at that lookahead depth
81 public int trueCaseLA(final int i) {
85 private void load(final File file, final String encoding) throws IOException {
89 final int size = (int) file.length();
90 InputStreamReader isr;
91 final FileInputStream fis = new FileInputStream(file);
92 if (encoding != null) {
93 isr = new InputStreamReader(fis, encoding);
95 isr = new InputStreamReader(fis);
98 data = new char[size];
99 super.n = isr.read(data);
105 public String getSourceName() {