|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| package com.unitesk.atp.tree.tool.antlr; |
|
33 |
| |
|
34 |
| import java.io.FilterReader; |
|
35 |
| import java.io.IOException; |
|
36 |
| import java.io.Reader; |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| public class JavaUnicodeEscapeFilterReader extends FilterReader |
|
47 |
| { |
|
48 |
0
| public JavaUnicodeEscapeFilterReader(Reader in)
|
|
49 |
| { |
|
50 |
0
| super( in );
|
|
51 |
| } |
|
52 |
| |
|
53 |
0
| private static int hex2int( int d ) throws IOException
|
|
54 |
| { |
|
55 |
0
| switch( d )
|
|
56 |
| { |
|
57 |
0
| case '0': return 0;
|
|
58 |
0
| case '1': return 1;
|
|
59 |
0
| case '2': return 2;
|
|
60 |
0
| case '3': return 3;
|
|
61 |
0
| case '4': return 4;
|
|
62 |
0
| case '5': return 5;
|
|
63 |
0
| case '6': return 6;
|
|
64 |
0
| case '7': return 7;
|
|
65 |
0
| case '8': return 8;
|
|
66 |
0
| case '9': return 9;
|
|
67 |
0
| case 'a':
|
|
68 |
0
| case 'A': return 10;
|
|
69 |
0
| case 'b':
|
|
70 |
0
| case 'B': return 11;
|
|
71 |
0
| case 'c':
|
|
72 |
0
| case 'C': return 12;
|
|
73 |
0
| case 'd':
|
|
74 |
0
| case 'D': return 13;
|
|
75 |
0
| case 'e':
|
|
76 |
0
| case 'E': return 14;
|
|
77 |
0
| case 'f':
|
|
78 |
0
| case 'F': return 15;
|
|
79 |
0
| default:
|
|
80 |
0
| throw new IOException( "illegal hex: " + d );
|
|
81 |
| } |
|
82 |
| } |
|
83 |
| |
|
84 |
| private int count; |
|
85 |
| private int buf; |
|
86 |
| |
|
87 |
| private static final boolean debug = false; |
|
88 |
| |
|
89 |
0
| public int read() throws IOException
|
|
90 |
| { |
|
91 |
0
| if( count > 0 )
|
|
92 |
| { |
|
93 |
0
| count--;
|
|
94 |
0
| if( debug ) System.out.print( (char)buf );
|
|
95 |
0
| return buf;
|
|
96 |
| } |
|
97 |
0
| int d = super.read();
|
|
98 |
0
| if( d != '\\' )
|
|
99 |
| { |
|
100 |
0
| if( debug ) System.out.print( (char)d );
|
|
101 |
0
| return d;
|
|
102 |
| } |
|
103 |
0
| int value = 0;
|
|
104 |
0
| if( (d = super.read()) != 'u' )
|
|
105 |
| { |
|
106 |
0
| count++;
|
|
107 |
0
| buf = d;
|
|
108 |
0
| if( debug ) System.out.print( '\\' );
|
|
109 |
0
| return '\\';
|
|
110 |
| } |
|
111 |
0
| while( (d = super.read()) == 'u' ) {}
|
|
112 |
0
| value = hex2int( d );
|
|
113 |
0
| value = value * 16 + hex2int( super.read() );
|
|
114 |
0
| value = value * 16 + hex2int( super.read() );
|
|
115 |
0
| value = value * 16 + hex2int( super.read() );
|
|
116 |
0
| if( debug ) System.out.print( "\\u" + Integer.toHexString( value ) );
|
|
117 |
0
| return value;
|
|
118 |
| } |
|
119 |
| |
|
120 |
0
| public int read( char[] cbuf, int off, int len ) throws IOException
|
|
121 |
| { |
|
122 |
0
| for( int i = off; i < off + len; i++ )
|
|
123 |
| { |
|
124 |
0
| cbuf[i] = (char)read();
|
|
125 |
| } |
|
126 |
0
| return len;
|
|
127 |
| } |
|
128 |
| |
|
129 |
0
| public long skip( long n ) throws IOException
|
|
130 |
| { |
|
131 |
0
| long res = n;
|
|
132 |
0
| while( n-- > 0 ) read();
|
|
133 |
0
| return res;
|
|
134 |
| } |
|
135 |
| |
|
136 |
0
| public int read( char[] cbuf ) throws IOException
|
|
137 |
| { |
|
138 |
0
| return read( cbuf, 0, cbuf.length );
|
|
139 |
| } |
|
140 |
| } |