01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 1997-1999 Raja Vallee-Rai
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: */
19:
20: /*
21: * Modified by the Sable Research Group and others 1997-1999.
22: * See the 'credits' file distributed with Soot for the complete list of
23: * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24: */
25:
26: package soot.util;
27:
28: import java.io.*;
29:
30: /** A FilterReader which catches escaped characters (<code>\\unnnn</code>) in the
31: * input and de-escapes them. Used in the Jimple Parser. */
32: public class EscapedReader extends FilterReader {
33: /** Constructs an EscapedReader around the given Reader. */
34: public EscapedReader(Reader fos) {
35: super (fos);
36: }
37:
38: private StringBuffer mini = new StringBuffer();
39:
40: boolean nextF;
41: int nextch = 0;
42:
43: /** Reads a character from the input. */
44: public int read() throws IOException {
45: /* if you already read the char, just return it */
46: if (nextF) {
47: nextF = false;
48: return nextch;
49: }
50:
51: int ch = super .read();
52:
53: if (ch != '\\')
54: return ch;
55:
56: /* we may have an escape sequence here ..*/
57: mini = new StringBuffer();
58:
59: ch = super .read();
60: if (ch != 'u') {
61: nextF = true;
62: nextch = ch;
63: return '\\';
64: }
65:
66: mini.append("\\u");
67: while (mini.length() < 6) {
68: ch = super .read();
69: mini.append((char) ch);
70: }
71:
72: // G.v().out.println(mini.toString());
73: ch = Integer.parseInt(mini.substring(2).toString(), 16);
74:
75: return ch;
76: }
77: }
|