|
1 | 1 | package com.jsoniter; |
2 | 2 |
|
3 | | -import java.io.ByteArrayOutputStream; |
4 | 3 | import java.io.IOException; |
5 | 4 |
|
6 | | -import static java.lang.Character.MIN_HIGH_SURROGATE; |
7 | | -import static java.lang.Character.MIN_LOW_SURROGATE; |
8 | | -import static java.lang.Character.MIN_SUPPLEMENTARY_CODE_POINT; |
| 5 | +import static java.lang.Character.*; |
9 | 6 |
|
10 | 7 | class IterImplString { |
11 | 8 |
|
12 | | - static int[] base64Tbl = { |
13 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
14 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
15 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, |
16 | | - 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, |
17 | | - 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, |
18 | | - 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, |
19 | | - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, |
20 | | - 48, 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
21 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
22 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
23 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
24 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
25 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
26 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
27 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; |
28 | | - |
29 | 9 | public static final String readString(JsonIterator iter) throws IOException { |
30 | 10 | byte c = IterImpl.nextToken(iter); |
31 | 11 | if (c == '"') { |
@@ -156,50 +136,6 @@ private static char lowSurrogate(int codePoint) { |
156 | 136 | return (char) ((codePoint & 0x3ff) + MIN_LOW_SURROGATE); |
157 | 137 | } |
158 | 138 |
|
159 | | - public static final byte[] readBase64(JsonIterator iter) throws IOException { |
160 | | - // from https://gist.github.com/EmilHernvall/953733 |
161 | | - Slice slice = IterImpl.readSlice(iter); |
162 | | - if (slice == null) { |
163 | | - return null; |
164 | | - } |
165 | | - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); |
166 | | - int end = slice.tail(); |
167 | | - for (int i = slice.head(); i < end; i++) { |
168 | | - int b = 0; |
169 | | - if (base64Tbl[slice.data()[i]] != -1) { |
170 | | - b = (base64Tbl[slice.data()[i]] & 0xFF) << 18; |
171 | | - } |
172 | | - // skip unknown characters |
173 | | - else { |
174 | | - i++; |
175 | | - continue; |
176 | | - } |
177 | | - |
178 | | - int num = 0; |
179 | | - if (i + 1 < end && base64Tbl[slice.data()[i + 1]] != -1) { |
180 | | - b = b | ((base64Tbl[slice.data()[i + 1]] & 0xFF) << 12); |
181 | | - num++; |
182 | | - } |
183 | | - if (i + 2 < end && base64Tbl[slice.data()[i + 2]] != -1) { |
184 | | - b = b | ((base64Tbl[slice.data()[i + 2]] & 0xFF) << 6); |
185 | | - num++; |
186 | | - } |
187 | | - if (i + 3 < end && base64Tbl[slice.data()[i + 3]] != -1) { |
188 | | - b = b | (base64Tbl[slice.data()[i + 3]] & 0xFF); |
189 | | - num++; |
190 | | - } |
191 | | - |
192 | | - while (num > 0) { |
193 | | - int c = (b & 0xFF0000) >> 16; |
194 | | - buffer.write((char) c); |
195 | | - b <<= 8; |
196 | | - num--; |
197 | | - } |
198 | | - i += 4; |
199 | | - } |
200 | | - return buffer.toByteArray(); |
201 | | - } |
202 | | - |
203 | 139 | // slice does not allow escape |
204 | 140 | final static int findSliceEnd(JsonIterator iter) { |
205 | 141 | for (int i = iter.head; i < iter.tail; i++) { |
|
0 commit comments