OLD | NEW |
| (Empty) |
1 dart_library.library('dart/convert', null, /* Imports */[ | |
2 'dart/_runtime', | |
3 'dart/core', | |
4 'dart/async', | |
5 'dart/typed_data', | |
6 'dart/_internal', | |
7 'dart/collection' | |
8 ], /* Lazy imports */[ | |
9 ], function(exports, dart, core, async, typed_data, _internal, collection) { | |
10 'use strict'; | |
11 let dartx = dart.dartx; | |
12 const _allowInvalid = Symbol('_allowInvalid'); | |
13 const Codec$ = dart.generic(function(S, T) { | |
14 class Codec extends core.Object { | |
15 Codec() { | |
16 } | |
17 encode(input) { | |
18 dart.as(input, S); | |
19 return this.encoder.convert(input); | |
20 } | |
21 decode(encoded) { | |
22 dart.as(encoded, T); | |
23 return this.decoder.convert(encoded); | |
24 } | |
25 fuse(other) { | |
26 dart.as(other, Codec$(T, dart.dynamic)); | |
27 return new (_FusedCodec$(S, T, dart.dynamic))(this, other); | |
28 } | |
29 get inverted() { | |
30 return new (_InvertedCodec$(T, S))(this); | |
31 } | |
32 } | |
33 dart.setSignature(Codec, { | |
34 constructors: () => ({Codec: [Codec$(S, T), []]}), | |
35 methods: () => ({ | |
36 encode: [T, [S]], | |
37 decode: [S, [T]], | |
38 fuse: [Codec$(S, dart.dynamic), [Codec$(T, dart.dynamic)]] | |
39 }) | |
40 }); | |
41 return Codec; | |
42 }); | |
43 let Codec = Codec$(); | |
44 class Encoding extends Codec$(core.String, core.List$(core.int)) { | |
45 Encoding() { | |
46 super.Codec(); | |
47 } | |
48 decodeStream(byteStream) { | |
49 return byteStream.transform(this.decoder).fold(new core.StringBuffer(), da
rt.fn((buffer, string) => ((() => { | |
50 dart.dsend(buffer, 'write', string); | |
51 return buffer; | |
52 })()), dart.dynamic, [dart.dynamic, core.String])).then(dart.fn(buffer =>
dart.toString(buffer), core.String, [dart.dynamic])); | |
53 } | |
54 static getByName(name) { | |
55 if (name == null) return null; | |
56 name = name[dartx.toLowerCase](); | |
57 return Encoding._nameToEncoding[dartx.get](name); | |
58 } | |
59 } | |
60 dart.setSignature(Encoding, { | |
61 constructors: () => ({Encoding: [Encoding, []]}), | |
62 methods: () => ({decodeStream: [async.Future$(core.String), [async.Stream$(c
ore.List$(core.int))]]}), | |
63 statics: () => ({getByName: [Encoding, [core.String]]}), | |
64 names: ['getByName'] | |
65 }); | |
66 dart.defineLazyProperties(Encoding, { | |
67 get _nameToEncoding() { | |
68 return dart.map({"iso_8859-1:1987": LATIN1, "iso-ir-100": LATIN1, "iso_885
9-1": LATIN1, "iso-8859-1": LATIN1, latin1: LATIN1, l1: LATIN1, ibm819: LATIN1,
cp819: LATIN1, csisolatin1: LATIN1, "iso-ir-6": ASCII, "ansi_x3.4-1968": ASCII,
"ansi_x3.4-1986": ASCII, "iso_646.irv:1991": ASCII, "iso646-us": ASCII, "us-asci
i": ASCII, us: ASCII, ibm367: ASCII, cp367: ASCII, csascii: ASCII, ascii: ASCII,
csutf8: UTF8, "utf-8": UTF8}, core.String, Encoding); | |
69 }, | |
70 set _nameToEncoding(_) {} | |
71 }); | |
72 class AsciiCodec extends Encoding { | |
73 AsciiCodec(opts) { | |
74 let allowInvalid = opts && 'allowInvalid' in opts ? opts.allowInvalid : fa
lse; | |
75 this[_allowInvalid] = allowInvalid; | |
76 super.Encoding(); | |
77 } | |
78 get name() { | |
79 return "us-ascii"; | |
80 } | |
81 decode(bytes, opts) { | |
82 let allowInvalid = opts && 'allowInvalid' in opts ? opts.allowInvalid : nu
ll; | |
83 if (allowInvalid == null) allowInvalid = this[_allowInvalid]; | |
84 if (dart.notNull(allowInvalid)) { | |
85 return dart.const(new AsciiDecoder({allowInvalid: true})).convert(bytes)
; | |
86 } else { | |
87 return dart.const(new AsciiDecoder({allowInvalid: false})).convert(bytes
); | |
88 } | |
89 } | |
90 get encoder() { | |
91 return dart.const(new AsciiEncoder()); | |
92 } | |
93 get decoder() { | |
94 return dart.notNull(this[_allowInvalid]) ? dart.const(new AsciiDecoder({al
lowInvalid: true})) : dart.const(new AsciiDecoder({allowInvalid: false})); | |
95 } | |
96 } | |
97 dart.setSignature(AsciiCodec, { | |
98 constructors: () => ({AsciiCodec: [AsciiCodec, [], {allowInvalid: core.bool}
]}), | |
99 methods: () => ({decode: [core.String, [core.List$(core.int)], {allowInvalid
: core.bool}]}) | |
100 }); | |
101 const ASCII = dart.const(new AsciiCodec()); | |
102 const _ASCII_MASK = 127; | |
103 const _subsetMask = Symbol('_subsetMask'); | |
104 const Converter$ = dart.generic(function(S, T) { | |
105 class Converter extends core.Object { | |
106 Converter() { | |
107 } | |
108 fuse(other) { | |
109 dart.as(other, Converter$(T, dart.dynamic)); | |
110 return new (_FusedConverter$(S, T, dart.dynamic))(this, other); | |
111 } | |
112 startChunkedConversion(sink) { | |
113 dart.as(sink, core.Sink$(T)); | |
114 dart.throw(new core.UnsupportedError(`This converter does not support ch
unked conversions: ${this}`)); | |
115 } | |
116 bind(source) { | |
117 dart.as(source, async.Stream$(S)); | |
118 return async.Stream$(T).eventTransformed(source, dart.fn(sink => new _Co
nverterStreamEventSink(this, sink), _ConverterStreamEventSink, [async.EventSink]
)); | |
119 } | |
120 } | |
121 Converter[dart.implements] = () => [async.StreamTransformer$(S, T)]; | |
122 dart.setSignature(Converter, { | |
123 constructors: () => ({Converter: [Converter$(S, T), []]}), | |
124 methods: () => ({ | |
125 fuse: [Converter$(S, dart.dynamic), [Converter$(T, dart.dynamic)]], | |
126 startChunkedConversion: [ChunkedConversionSink, [core.Sink$(T)]], | |
127 bind: [async.Stream$(T), [async.Stream$(S)]] | |
128 }) | |
129 }); | |
130 return Converter; | |
131 }); | |
132 let Converter = Converter$(); | |
133 class _UnicodeSubsetEncoder extends Converter$(core.String, core.List$(core.in
t)) { | |
134 _UnicodeSubsetEncoder(subsetMask) { | |
135 this[_subsetMask] = subsetMask; | |
136 super.Converter(); | |
137 } | |
138 convert(string, start, end) { | |
139 if (start === void 0) start = 0; | |
140 if (end === void 0) end = null; | |
141 let stringLength = string[dartx.length]; | |
142 core.RangeError.checkValidRange(start, end, stringLength); | |
143 if (end == null) end = stringLength; | |
144 let length = dart.notNull(end) - dart.notNull(start); | |
145 let result = typed_data.Uint8List.new(length); | |
146 for (let i = 0; i < length; i++) { | |
147 let codeUnit = string[dartx.codeUnitAt](dart.notNull(start) + i); | |
148 if ((dart.notNull(codeUnit) & ~dart.notNull(this[_subsetMask])) != 0) { | |
149 dart.throw(new core.ArgumentError("String contains invalid characters.
")); | |
150 } | |
151 result[dartx.set](i, codeUnit); | |
152 } | |
153 return dart.as(result, core.List$(core.int)); | |
154 } | |
155 startChunkedConversion(sink) { | |
156 if (!dart.is(sink, ByteConversionSink)) { | |
157 sink = ByteConversionSink.from(sink); | |
158 } | |
159 return new _UnicodeSubsetEncoderSink(this[_subsetMask], dart.as(sink, Byte
ConversionSink)); | |
160 } | |
161 bind(stream) { | |
162 return super.bind(stream); | |
163 } | |
164 } | |
165 dart.setSignature(_UnicodeSubsetEncoder, { | |
166 constructors: () => ({_UnicodeSubsetEncoder: [_UnicodeSubsetEncoder, [core.i
nt]]}), | |
167 methods: () => ({ | |
168 convert: [core.List$(core.int), [core.String], [core.int, core.int]], | |
169 startChunkedConversion: [StringConversionSink, [core.Sink$(core.List$(core
.int))]], | |
170 bind: [async.Stream$(core.List$(core.int)), [async.Stream$(core.String)]] | |
171 }) | |
172 }); | |
173 class AsciiEncoder extends _UnicodeSubsetEncoder { | |
174 AsciiEncoder() { | |
175 super._UnicodeSubsetEncoder(_ASCII_MASK); | |
176 } | |
177 } | |
178 dart.setSignature(AsciiEncoder, { | |
179 constructors: () => ({AsciiEncoder: [AsciiEncoder, []]}) | |
180 }); | |
181 const _sink = Symbol('_sink'); | |
182 class StringConversionSinkMixin extends core.Object { | |
183 add(str) { | |
184 return this.addSlice(str, 0, str[dartx.length], false); | |
185 } | |
186 asUtf8Sink(allowMalformed) { | |
187 return new _Utf8ConversionSink(this, allowMalformed); | |
188 } | |
189 asStringSink() { | |
190 return new _StringConversionSinkAsStringSinkAdapter(this); | |
191 } | |
192 } | |
193 StringConversionSinkMixin[dart.implements] = () => [StringConversionSink]; | |
194 dart.setSignature(StringConversionSinkMixin, { | |
195 methods: () => ({ | |
196 add: [dart.void, [core.String]], | |
197 asUtf8Sink: [ByteConversionSink, [core.bool]], | |
198 asStringSink: [ClosableStringSink, []] | |
199 }) | |
200 }); | |
201 class StringConversionSinkBase extends StringConversionSinkMixin {} | |
202 class _UnicodeSubsetEncoderSink extends StringConversionSinkBase { | |
203 _UnicodeSubsetEncoderSink(subsetMask, sink) { | |
204 this[_subsetMask] = subsetMask; | |
205 this[_sink] = sink; | |
206 } | |
207 close() { | |
208 this[_sink].close(); | |
209 } | |
210 addSlice(source, start, end, isLast) { | |
211 core.RangeError.checkValidRange(start, end, source[dartx.length]); | |
212 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(
i) + 1) { | |
213 let codeUnit = source[dartx.codeUnitAt](i); | |
214 if ((dart.notNull(codeUnit) & ~dart.notNull(this[_subsetMask])) != 0) { | |
215 dart.throw(new core.ArgumentError(`Source contains invalid character w
ith code point: ${codeUnit}.`)); | |
216 } | |
217 } | |
218 this[_sink].add(source[dartx.codeUnits][dartx.sublist](start, end)); | |
219 if (dart.notNull(isLast)) { | |
220 this.close(); | |
221 } | |
222 } | |
223 } | |
224 dart.setSignature(_UnicodeSubsetEncoderSink, { | |
225 constructors: () => ({_UnicodeSubsetEncoderSink: [_UnicodeSubsetEncoderSink,
[core.int, ByteConversionSink]]}), | |
226 methods: () => ({ | |
227 close: [dart.void, []], | |
228 addSlice: [dart.void, [core.String, core.int, core.int, core.bool]] | |
229 }) | |
230 }); | |
231 const _convertInvalid = Symbol('_convertInvalid'); | |
232 class _UnicodeSubsetDecoder extends Converter$(core.List$(core.int), core.Stri
ng) { | |
233 _UnicodeSubsetDecoder(allowInvalid, subsetMask) { | |
234 this[_allowInvalid] = allowInvalid; | |
235 this[_subsetMask] = subsetMask; | |
236 super.Converter(); | |
237 } | |
238 convert(bytes, start, end) { | |
239 if (start === void 0) start = 0; | |
240 if (end === void 0) end = null; | |
241 let byteCount = bytes[dartx.length]; | |
242 core.RangeError.checkValidRange(start, end, byteCount); | |
243 if (end == null) end = byteCount; | |
244 let length = dart.notNull(end) - dart.notNull(start); | |
245 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(
i) + 1) { | |
246 let byte = bytes[dartx.get](i); | |
247 if ((dart.notNull(byte) & ~dart.notNull(this[_subsetMask])) != 0) { | |
248 if (!dart.notNull(this[_allowInvalid])) { | |
249 dart.throw(new core.FormatException(`Invalid value in input: ${byte}
`)); | |
250 } | |
251 return this[_convertInvalid](bytes, start, end); | |
252 } | |
253 } | |
254 return core.String.fromCharCodes(bytes, start, end); | |
255 } | |
256 [_convertInvalid](bytes, start, end) { | |
257 let buffer = new core.StringBuffer(); | |
258 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(
i) + 1) { | |
259 let value = bytes[dartx.get](i); | |
260 if ((dart.notNull(value) & ~dart.notNull(this[_subsetMask])) != 0) value
= 65533; | |
261 buffer.writeCharCode(value); | |
262 } | |
263 return buffer.toString(); | |
264 } | |
265 bind(stream) { | |
266 return super.bind(stream); | |
267 } | |
268 } | |
269 dart.setSignature(_UnicodeSubsetDecoder, { | |
270 constructors: () => ({_UnicodeSubsetDecoder: [_UnicodeSubsetDecoder, [core.b
ool, core.int]]}), | |
271 methods: () => ({ | |
272 convert: [core.String, [core.List$(core.int)], [core.int, core.int]], | |
273 [_convertInvalid]: [core.String, [core.List$(core.int), core.int, core.int
]], | |
274 bind: [async.Stream$(core.String), [async.Stream$(core.List$(core.int))]] | |
275 }) | |
276 }); | |
277 class AsciiDecoder extends _UnicodeSubsetDecoder { | |
278 AsciiDecoder(opts) { | |
279 let allowInvalid = opts && 'allowInvalid' in opts ? opts.allowInvalid : fa
lse; | |
280 super._UnicodeSubsetDecoder(allowInvalid, _ASCII_MASK); | |
281 } | |
282 startChunkedConversion(sink) { | |
283 let stringSink = null; | |
284 if (dart.is(sink, StringConversionSink)) { | |
285 stringSink = sink; | |
286 } else { | |
287 stringSink = StringConversionSink.from(sink); | |
288 } | |
289 if (dart.notNull(this[_allowInvalid])) { | |
290 return new _ErrorHandlingAsciiDecoderSink(stringSink.asUtf8Sink(false)); | |
291 } else { | |
292 return new _SimpleAsciiDecoderSink(stringSink); | |
293 } | |
294 } | |
295 } | |
296 dart.setSignature(AsciiDecoder, { | |
297 constructors: () => ({AsciiDecoder: [AsciiDecoder, [], {allowInvalid: core.b
ool}]}), | |
298 methods: () => ({startChunkedConversion: [ByteConversionSink, [core.Sink$(co
re.String)]]}) | |
299 }); | |
300 const _utf8Sink = Symbol('_utf8Sink'); | |
301 const ChunkedConversionSink$ = dart.generic(function(T) { | |
302 class ChunkedConversionSink extends core.Object { | |
303 ChunkedConversionSink() { | |
304 } | |
305 static withCallback(callback) { | |
306 return new (_SimpleCallbackSink$(T))(callback); | |
307 } | |
308 } | |
309 ChunkedConversionSink[dart.implements] = () => [core.Sink$(T)]; | |
310 dart.setSignature(ChunkedConversionSink, { | |
311 constructors: () => ({ | |
312 ChunkedConversionSink: [ChunkedConversionSink$(T), []], | |
313 withCallback: [ChunkedConversionSink$(T), [dart.functionType(dart.void,
[core.List$(T)])]] | |
314 }) | |
315 }); | |
316 return ChunkedConversionSink; | |
317 }); | |
318 let ChunkedConversionSink = ChunkedConversionSink$(); | |
319 class ByteConversionSink extends ChunkedConversionSink$(core.List$(core.int))
{ | |
320 ByteConversionSink() { | |
321 super.ChunkedConversionSink(); | |
322 } | |
323 static withCallback(callback) { | |
324 return new _ByteCallbackSink(callback); | |
325 } | |
326 static from(sink) { | |
327 return new _ByteAdapterSink(sink); | |
328 } | |
329 } | |
330 dart.setSignature(ByteConversionSink, { | |
331 constructors: () => ({ | |
332 ByteConversionSink: [ByteConversionSink, []], | |
333 withCallback: [ByteConversionSink, [dart.functionType(dart.void, [core.Lis
t$(core.int)])]], | |
334 from: [ByteConversionSink, [core.Sink$(core.List$(core.int))]] | |
335 }) | |
336 }); | |
337 class ByteConversionSinkBase extends ByteConversionSink { | |
338 ByteConversionSinkBase() { | |
339 super.ByteConversionSink(); | |
340 } | |
341 addSlice(chunk, start, end, isLast) { | |
342 this.add(chunk[dartx.sublist](start, end)); | |
343 if (dart.notNull(isLast)) this.close(); | |
344 } | |
345 } | |
346 dart.setSignature(ByteConversionSinkBase, { | |
347 methods: () => ({addSlice: [dart.void, [core.List$(core.int), core.int, core
.int, core.bool]]}) | |
348 }); | |
349 class _ErrorHandlingAsciiDecoderSink extends ByteConversionSinkBase { | |
350 _ErrorHandlingAsciiDecoderSink(utf8Sink) { | |
351 this[_utf8Sink] = utf8Sink; | |
352 } | |
353 close() { | |
354 this[_utf8Sink].close(); | |
355 } | |
356 add(source) { | |
357 this.addSlice(source, 0, source[dartx.length], false); | |
358 } | |
359 addSlice(source, start, end, isLast) { | |
360 core.RangeError.checkValidRange(start, end, source[dartx.length]); | |
361 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(
i) + 1) { | |
362 if ((dart.notNull(source[dartx.get](i)) & ~dart.notNull(_ASCII_MASK)) !=
0) { | |
363 if (dart.notNull(i) > dart.notNull(start)) this[_utf8Sink].addSlice(so
urce, start, i, false); | |
364 this[_utf8Sink].add(dart.const(dart.list([239, 191, 189], core.int))); | |
365 start = dart.notNull(i) + 1; | |
366 } | |
367 } | |
368 if (dart.notNull(start) < dart.notNull(end)) { | |
369 this[_utf8Sink].addSlice(source, start, end, isLast); | |
370 } else if (dart.notNull(isLast)) { | |
371 this.close(); | |
372 } | |
373 } | |
374 } | |
375 dart.setSignature(_ErrorHandlingAsciiDecoderSink, { | |
376 constructors: () => ({_ErrorHandlingAsciiDecoderSink: [_ErrorHandlingAsciiDe
coderSink, [ByteConversionSink]]}), | |
377 methods: () => ({ | |
378 close: [dart.void, []], | |
379 add: [dart.void, [core.List$(core.int)]] | |
380 }) | |
381 }); | |
382 class _SimpleAsciiDecoderSink extends ByteConversionSinkBase { | |
383 _SimpleAsciiDecoderSink(sink) { | |
384 this[_sink] = sink; | |
385 } | |
386 close() { | |
387 this[_sink].close(); | |
388 } | |
389 add(source) { | |
390 for (let i = 0; i < dart.notNull(source[dartx.length]); i++) { | |
391 if ((dart.notNull(source[dartx.get](i)) & ~dart.notNull(_ASCII_MASK)) !=
0) { | |
392 dart.throw(new core.FormatException("Source contains non-ASCII bytes."
)); | |
393 } | |
394 } | |
395 this[_sink].add(core.String.fromCharCodes(source)); | |
396 } | |
397 addSlice(source, start, end, isLast) { | |
398 let length = source[dartx.length]; | |
399 core.RangeError.checkValidRange(start, end, length); | |
400 if (dart.notNull(start) < dart.notNull(end)) { | |
401 if (start != 0 || end != length) { | |
402 source = source[dartx.sublist](start, end); | |
403 } | |
404 this.add(source); | |
405 } | |
406 if (dart.notNull(isLast)) this.close(); | |
407 } | |
408 } | |
409 dart.setSignature(_SimpleAsciiDecoderSink, { | |
410 constructors: () => ({_SimpleAsciiDecoderSink: [_SimpleAsciiDecoderSink, [co
re.Sink]]}), | |
411 methods: () => ({ | |
412 close: [dart.void, []], | |
413 add: [dart.void, [core.List$(core.int)]] | |
414 }) | |
415 }); | |
416 class _ByteAdapterSink extends ByteConversionSinkBase { | |
417 _ByteAdapterSink(sink) { | |
418 this[_sink] = sink; | |
419 } | |
420 add(chunk) { | |
421 return this[_sink].add(chunk); | |
422 } | |
423 close() { | |
424 return this[_sink].close(); | |
425 } | |
426 } | |
427 dart.setSignature(_ByteAdapterSink, { | |
428 constructors: () => ({_ByteAdapterSink: [_ByteAdapterSink, [core.Sink$(core.
List$(core.int))]]}), | |
429 methods: () => ({ | |
430 add: [dart.void, [core.List$(core.int)]], | |
431 close: [dart.void, []] | |
432 }) | |
433 }); | |
434 const _buffer = Symbol('_buffer'); | |
435 const _callback = Symbol('_callback'); | |
436 const _bufferIndex = Symbol('_bufferIndex'); | |
437 class _ByteCallbackSink extends ByteConversionSinkBase { | |
438 _ByteCallbackSink(callback) { | |
439 this[_buffer] = typed_data.Uint8List.new(_ByteCallbackSink._INITIAL_BUFFER
_SIZE); | |
440 this[_callback] = callback; | |
441 this[_bufferIndex] = 0; | |
442 } | |
443 add(chunk) { | |
444 let freeCount = dart.notNull(this[_buffer][dartx.length]) - dart.notNull(t
his[_bufferIndex]); | |
445 if (dart.notNull(chunk[dartx.length]) > freeCount) { | |
446 let oldLength = this[_buffer][dartx.length]; | |
447 let newLength = dart.notNull(_ByteCallbackSink._roundToPowerOf2(dart.not
Null(chunk[dartx.length]) + dart.notNull(oldLength))) * 2; | |
448 let grown = typed_data.Uint8List.new(newLength); | |
449 grown[dartx.setRange](0, this[_buffer][dartx.length], this[_buffer]); | |
450 this[_buffer] = grown; | |
451 } | |
452 this[_buffer][dartx.setRange](this[_bufferIndex], dart.notNull(this[_buffe
rIndex]) + dart.notNull(chunk[dartx.length]), chunk); | |
453 this[_bufferIndex] = dart.notNull(this[_bufferIndex]) + dart.notNull(chunk
[dartx.length]); | |
454 } | |
455 static _roundToPowerOf2(v) { | |
456 dart.assert(dart.notNull(v) > 0); | |
457 v = dart.notNull(v) - 1; | |
458 v = dart.notNull(v) | dart.notNull(v) >> 1; | |
459 v = dart.notNull(v) | dart.notNull(v) >> 2; | |
460 v = dart.notNull(v) | dart.notNull(v) >> 4; | |
461 v = dart.notNull(v) | dart.notNull(v) >> 8; | |
462 v = dart.notNull(v) | dart.notNull(v) >> 16; | |
463 v = dart.notNull(v) + 1; | |
464 return v; | |
465 } | |
466 close() { | |
467 this[_callback](this[_buffer][dartx.sublist](0, this[_bufferIndex])); | |
468 } | |
469 } | |
470 dart.setSignature(_ByteCallbackSink, { | |
471 constructors: () => ({_ByteCallbackSink: [_ByteCallbackSink, [dart.functionT
ype(dart.void, [core.List$(core.int)])]]}), | |
472 methods: () => ({ | |
473 add: [dart.void, [core.Iterable$(core.int)]], | |
474 close: [dart.void, []] | |
475 }), | |
476 statics: () => ({_roundToPowerOf2: [core.int, [core.int]]}), | |
477 names: ['_roundToPowerOf2'] | |
478 }); | |
479 _ByteCallbackSink._INITIAL_BUFFER_SIZE = 1024; | |
480 const _ChunkedConversionCallback$ = dart.generic(function(T) { | |
481 const _ChunkedConversionCallback = dart.typedef('_ChunkedConversionCallback'
, () => dart.functionType(dart.void, [T])); | |
482 return _ChunkedConversionCallback; | |
483 }); | |
484 let _ChunkedConversionCallback = _ChunkedConversionCallback$(); | |
485 const _accumulated = Symbol('_accumulated'); | |
486 const _SimpleCallbackSink$ = dart.generic(function(T) { | |
487 class _SimpleCallbackSink extends ChunkedConversionSink$(T) { | |
488 _SimpleCallbackSink(callback) { | |
489 this[_accumulated] = dart.list([], T); | |
490 this[_callback] = callback; | |
491 super.ChunkedConversionSink(); | |
492 } | |
493 add(chunk) { | |
494 dart.as(chunk, T); | |
495 this[_accumulated][dartx.add](chunk); | |
496 } | |
497 close() { | |
498 this[_callback](this[_accumulated]); | |
499 } | |
500 } | |
501 dart.setSignature(_SimpleCallbackSink, { | |
502 constructors: () => ({_SimpleCallbackSink: [_SimpleCallbackSink$(T), [_Chu
nkedConversionCallback$(core.List$(T))]]}), | |
503 methods: () => ({ | |
504 add: [dart.void, [T]], | |
505 close: [dart.void, []] | |
506 }) | |
507 }); | |
508 return _SimpleCallbackSink; | |
509 }); | |
510 let _SimpleCallbackSink = _SimpleCallbackSink$(); | |
511 const _EventSinkAdapter$ = dart.generic(function(T) { | |
512 class _EventSinkAdapter extends core.Object { | |
513 _EventSinkAdapter(sink) { | |
514 this[_sink] = sink; | |
515 } | |
516 add(data) { | |
517 dart.as(data, T); | |
518 return this[_sink].add(data); | |
519 } | |
520 close() { | |
521 return this[_sink].close(); | |
522 } | |
523 } | |
524 _EventSinkAdapter[dart.implements] = () => [ChunkedConversionSink$(T)]; | |
525 dart.setSignature(_EventSinkAdapter, { | |
526 constructors: () => ({_EventSinkAdapter: [_EventSinkAdapter$(T), [async.Ev
entSink$(T)]]}), | |
527 methods: () => ({ | |
528 add: [dart.void, [T]], | |
529 close: [dart.void, []] | |
530 }) | |
531 }); | |
532 return _EventSinkAdapter; | |
533 }); | |
534 let _EventSinkAdapter = _EventSinkAdapter$(); | |
535 const _eventSink = Symbol('_eventSink'); | |
536 const _chunkedSink = Symbol('_chunkedSink'); | |
537 const _ConverterStreamEventSink$ = dart.generic(function(S, T) { | |
538 class _ConverterStreamEventSink extends core.Object { | |
539 _ConverterStreamEventSink(converter, sink) { | |
540 this[_eventSink] = sink; | |
541 this[_chunkedSink] = converter.startChunkedConversion(sink); | |
542 } | |
543 add(o) { | |
544 dart.as(o, S); | |
545 return this[_chunkedSink].add(o); | |
546 } | |
547 addError(error, stackTrace) { | |
548 if (stackTrace === void 0) stackTrace = null; | |
549 this[_eventSink].addError(error, stackTrace); | |
550 } | |
551 close() { | |
552 return this[_chunkedSink].close(); | |
553 } | |
554 } | |
555 _ConverterStreamEventSink[dart.implements] = () => [async.EventSink$(S)]; | |
556 dart.setSignature(_ConverterStreamEventSink, { | |
557 constructors: () => ({_ConverterStreamEventSink: [_ConverterStreamEventSin
k$(S, T), [Converter, async.EventSink$(T)]]}), | |
558 methods: () => ({ | |
559 add: [dart.void, [S]], | |
560 addError: [dart.void, [core.Object], [core.StackTrace]], | |
561 close: [dart.void, []] | |
562 }) | |
563 }); | |
564 return _ConverterStreamEventSink; | |
565 }); | |
566 let _ConverterStreamEventSink = _ConverterStreamEventSink$(); | |
567 const _first = Symbol('_first'); | |
568 const _second = Symbol('_second'); | |
569 const _FusedCodec$ = dart.generic(function(S, M, T) { | |
570 class _FusedCodec extends Codec$(S, T) { | |
571 get encoder() { | |
572 return dart.as(this[_first].encoder.fuse(this[_second].encoder), Convert
er$(S, T)); | |
573 } | |
574 get decoder() { | |
575 return dart.as(this[_second].decoder.fuse(this[_first].decoder), Convert
er$(T, S)); | |
576 } | |
577 _FusedCodec(first, second) { | |
578 this[_first] = first; | |
579 this[_second] = second; | |
580 super.Codec(); | |
581 } | |
582 } | |
583 dart.setSignature(_FusedCodec, { | |
584 constructors: () => ({_FusedCodec: [_FusedCodec$(S, M, T), [Codec$(S, M),
Codec$(M, T)]]}) | |
585 }); | |
586 return _FusedCodec; | |
587 }); | |
588 let _FusedCodec = _FusedCodec$(); | |
589 const _codec = Symbol('_codec'); | |
590 const _InvertedCodec$ = dart.generic(function(T, S) { | |
591 class _InvertedCodec extends Codec$(T, S) { | |
592 _InvertedCodec(codec) { | |
593 this[_codec] = codec; | |
594 super.Codec(); | |
595 } | |
596 get encoder() { | |
597 return this[_codec].decoder; | |
598 } | |
599 get decoder() { | |
600 return this[_codec].encoder; | |
601 } | |
602 get inverted() { | |
603 return this[_codec]; | |
604 } | |
605 } | |
606 dart.setSignature(_InvertedCodec, { | |
607 constructors: () => ({_InvertedCodec: [_InvertedCodec$(T, S), [Codec$(S, T
)]]}) | |
608 }); | |
609 return _InvertedCodec; | |
610 }); | |
611 let _InvertedCodec = _InvertedCodec$(); | |
612 const _FusedConverter$ = dart.generic(function(S, M, T) { | |
613 class _FusedConverter extends Converter$(S, T) { | |
614 _FusedConverter(first, second) { | |
615 this[_first] = first; | |
616 this[_second] = second; | |
617 super.Converter(); | |
618 } | |
619 convert(input) { | |
620 dart.as(input, S); | |
621 return dart.as(this[_second].convert(this[_first].convert(input)), T); | |
622 } | |
623 startChunkedConversion(sink) { | |
624 dart.as(sink, core.Sink$(T)); | |
625 return this[_first].startChunkedConversion(this[_second].startChunkedCon
version(sink)); | |
626 } | |
627 } | |
628 dart.setSignature(_FusedConverter, { | |
629 constructors: () => ({_FusedConverter: [_FusedConverter$(S, M, T), [Conver
ter, Converter]]}), | |
630 methods: () => ({ | |
631 convert: [T, [S]], | |
632 startChunkedConversion: [ChunkedConversionSink, [core.Sink$(T)]] | |
633 }) | |
634 }); | |
635 return _FusedConverter; | |
636 }); | |
637 let _FusedConverter = _FusedConverter$(); | |
638 const _name = Symbol('_name'); | |
639 class HtmlEscapeMode extends core.Object { | |
640 _(name, escapeLtGt, escapeQuot, escapeApos, escapeSlash) { | |
641 this[_name] = name; | |
642 this.escapeLtGt = escapeLtGt; | |
643 this.escapeQuot = escapeQuot; | |
644 this.escapeApos = escapeApos; | |
645 this.escapeSlash = escapeSlash; | |
646 } | |
647 toString() { | |
648 return this[_name]; | |
649 } | |
650 } | |
651 dart.defineNamedConstructor(HtmlEscapeMode, '_'); | |
652 dart.setSignature(HtmlEscapeMode, { | |
653 constructors: () => ({_: [HtmlEscapeMode, [core.String, core.bool, core.bool
, core.bool, core.bool]]}) | |
654 }); | |
655 dart.defineLazyProperties(HtmlEscapeMode, { | |
656 get UNKNOWN() { | |
657 return dart.const(new HtmlEscapeMode._('unknown', true, true, true, true))
; | |
658 }, | |
659 get ATTRIBUTE() { | |
660 return dart.const(new HtmlEscapeMode._('attribute', false, true, false, fa
lse)); | |
661 }, | |
662 get ELEMENT() { | |
663 return dart.const(new HtmlEscapeMode._('element', true, false, false, true
)); | |
664 } | |
665 }); | |
666 const _convert = Symbol('_convert'); | |
667 class HtmlEscape extends Converter$(core.String, core.String) { | |
668 HtmlEscape(mode) { | |
669 if (mode === void 0) mode = HtmlEscapeMode.UNKNOWN; | |
670 this.mode = mode; | |
671 super.Converter(); | |
672 } | |
673 convert(text) { | |
674 let val = this[_convert](text, 0, text[dartx.length]); | |
675 return val == null ? text : val; | |
676 } | |
677 [_convert](text, start, end) { | |
678 let result = null; | |
679 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(
i) + 1) { | |
680 let ch = text[dartx.get](i); | |
681 let replace = null; | |
682 switch (ch) { | |
683 case '&': | |
684 { | |
685 replace = '&'; | |
686 break; | |
687 } | |
688 case 'Â ': | |
689 { | |
690 replace = ' '; | |
691 break; | |
692 } | |
693 case '"': | |
694 { | |
695 if (dart.notNull(this.mode.escapeQuot)) replace = '"'; | |
696 break; | |
697 } | |
698 case "'": | |
699 { | |
700 if (dart.notNull(this.mode.escapeApos)) replace = '''; | |
701 break; | |
702 } | |
703 case '<': | |
704 { | |
705 if (dart.notNull(this.mode.escapeLtGt)) replace = '<'; | |
706 break; | |
707 } | |
708 case '>': | |
709 { | |
710 if (dart.notNull(this.mode.escapeLtGt)) replace = '>'; | |
711 break; | |
712 } | |
713 case '/': | |
714 { | |
715 if (dart.notNull(this.mode.escapeSlash)) replace = '/'; | |
716 break; | |
717 } | |
718 } | |
719 if (replace != null) { | |
720 if (result == null) result = new core.StringBuffer(text[dartx.substrin
g](start, i)); | |
721 result.write(replace); | |
722 } else if (result != null) { | |
723 result.write(ch); | |
724 } | |
725 } | |
726 return result != null ? dart.toString(result) : null; | |
727 } | |
728 startChunkedConversion(sink) { | |
729 if (!dart.is(sink, StringConversionSink)) { | |
730 sink = StringConversionSink.from(sink); | |
731 } | |
732 return new _HtmlEscapeSink(this, dart.as(sink, StringConversionSink)); | |
733 } | |
734 } | |
735 dart.setSignature(HtmlEscape, { | |
736 constructors: () => ({HtmlEscape: [HtmlEscape, [], [HtmlEscapeMode]]}), | |
737 methods: () => ({ | |
738 convert: [core.String, [core.String]], | |
739 [_convert]: [core.String, [core.String, core.int, core.int]], | |
740 startChunkedConversion: [StringConversionSink, [core.Sink$(core.String)]] | |
741 }) | |
742 }); | |
743 const HTML_ESCAPE = dart.const(new HtmlEscape()); | |
744 const _escape = Symbol('_escape'); | |
745 class _HtmlEscapeSink extends StringConversionSinkBase { | |
746 _HtmlEscapeSink(escape, sink) { | |
747 this[_escape] = escape; | |
748 this[_sink] = sink; | |
749 } | |
750 addSlice(chunk, start, end, isLast) { | |
751 let val = this[_escape][_convert](chunk, start, end); | |
752 if (val == null) { | |
753 this[_sink].addSlice(chunk, start, end, isLast); | |
754 } else { | |
755 this[_sink].add(val); | |
756 if (dart.notNull(isLast)) this[_sink].close(); | |
757 } | |
758 } | |
759 close() { | |
760 return this[_sink].close(); | |
761 } | |
762 } | |
763 dart.setSignature(_HtmlEscapeSink, { | |
764 constructors: () => ({_HtmlEscapeSink: [_HtmlEscapeSink, [HtmlEscape, String
ConversionSink]]}), | |
765 methods: () => ({ | |
766 addSlice: [dart.void, [core.String, core.int, core.int, core.bool]], | |
767 close: [dart.void, []] | |
768 }) | |
769 }); | |
770 class JsonUnsupportedObjectError extends core.Error { | |
771 JsonUnsupportedObjectError(unsupportedObject, opts) { | |
772 let cause = opts && 'cause' in opts ? opts.cause : null; | |
773 this.unsupportedObject = unsupportedObject; | |
774 this.cause = cause; | |
775 super.Error(); | |
776 } | |
777 toString() { | |
778 if (this.cause != null) { | |
779 return "Converting object to an encodable object failed."; | |
780 } else { | |
781 return "Converting object did not return an encodable object."; | |
782 } | |
783 } | |
784 } | |
785 dart.setSignature(JsonUnsupportedObjectError, { | |
786 constructors: () => ({JsonUnsupportedObjectError: [JsonUnsupportedObjectErro
r, [dart.dynamic], {cause: dart.dynamic}]}) | |
787 }); | |
788 class JsonCyclicError extends JsonUnsupportedObjectError { | |
789 JsonCyclicError(object) { | |
790 super.JsonUnsupportedObjectError(object); | |
791 } | |
792 toString() { | |
793 return "Cyclic error in JSON stringify"; | |
794 } | |
795 } | |
796 dart.setSignature(JsonCyclicError, { | |
797 constructors: () => ({JsonCyclicError: [JsonCyclicError, [core.Object]]}) | |
798 }); | |
799 const _reviver = Symbol('_reviver'); | |
800 const _toEncodable$ = Symbol('_toEncodable'); | |
801 class JsonCodec extends Codec$(core.Object, core.String) { | |
802 JsonCodec(opts) { | |
803 let reviver = opts && 'reviver' in opts ? opts.reviver : null; | |
804 let toEncodable = opts && 'toEncodable' in opts ? opts.toEncodable : null; | |
805 this[_reviver] = reviver; | |
806 this[_toEncodable$] = toEncodable; | |
807 super.Codec(); | |
808 } | |
809 withReviver(reviver) { | |
810 this.JsonCodec({reviver: reviver}); | |
811 } | |
812 decode(source, opts) { | |
813 let reviver = opts && 'reviver' in opts ? opts.reviver : null; | |
814 if (reviver == null) reviver = this[_reviver]; | |
815 if (reviver == null) return this.decoder.convert(source); | |
816 return new JsonDecoder(reviver).convert(source); | |
817 } | |
818 encode(value, opts) { | |
819 let toEncodable = opts && 'toEncodable' in opts ? opts.toEncodable : null; | |
820 if (toEncodable == null) toEncodable = this[_toEncodable$]; | |
821 if (toEncodable == null) return this.encoder.convert(value); | |
822 return new JsonEncoder(dart.as(toEncodable, dart.functionType(core.Object,
[core.Object]))).convert(value); | |
823 } | |
824 get encoder() { | |
825 if (this[_toEncodable$] == null) return dart.const(new JsonEncoder()); | |
826 return new JsonEncoder(dart.as(this[_toEncodable$], dart.functionType(core
.Object, [core.Object]))); | |
827 } | |
828 get decoder() { | |
829 if (this[_reviver] == null) return dart.const(new JsonDecoder()); | |
830 return new JsonDecoder(this[_reviver]); | |
831 } | |
832 } | |
833 dart.defineNamedConstructor(JsonCodec, 'withReviver'); | |
834 dart.setSignature(JsonCodec, { | |
835 constructors: () => ({ | |
836 JsonCodec: [JsonCodec, [], {reviver: dart.functionType(dart.dynamic, [dart
.dynamic, dart.dynamic]), toEncodable: dart.functionType(dart.dynamic, [dart.dyn
amic])}], | |
837 withReviver: [JsonCodec, [dart.functionType(dart.dynamic, [dart.dynamic, d
art.dynamic])]] | |
838 }), | |
839 methods: () => ({ | |
840 decode: [dart.dynamic, [core.String], {reviver: dart.functionType(dart.dyn
amic, [dart.dynamic, dart.dynamic])}], | |
841 encode: [core.String, [core.Object], {toEncodable: dart.functionType(dart.
dynamic, [dart.dynamic])}] | |
842 }) | |
843 }); | |
844 const JSON = dart.const(new JsonCodec()); | |
845 const _Reviver = dart.typedef('_Reviver', () => dart.functionType(dart.dynamic
, [dart.dynamic, dart.dynamic])); | |
846 const _ToEncodable = dart.typedef('_ToEncodable', () => dart.functionType(dart
.dynamic, [dart.dynamic])); | |
847 class JsonEncoder extends Converter$(core.Object, core.String) { | |
848 JsonEncoder(toEncodable) { | |
849 if (toEncodable === void 0) toEncodable = null; | |
850 this.indent = null; | |
851 this[_toEncodable$] = toEncodable; | |
852 super.Converter(); | |
853 } | |
854 withIndent(indent, toEncodable) { | |
855 if (toEncodable === void 0) toEncodable = null; | |
856 this.indent = indent; | |
857 this[_toEncodable$] = toEncodable; | |
858 super.Converter(); | |
859 } | |
860 convert(object) { | |
861 return _JsonStringStringifier.stringify(object, dart.as(this[_toEncodable$
], dart.functionType(dart.dynamic, [dart.dynamic])), this.indent); | |
862 } | |
863 startChunkedConversion(sink) { | |
864 if (!dart.is(sink, StringConversionSink)) { | |
865 sink = StringConversionSink.from(sink); | |
866 } else if (dart.is(sink, _Utf8EncoderSink)) { | |
867 return new _JsonUtf8EncoderSink(sink[_sink], this[_toEncodable$], JsonUt
f8Encoder._utf8Encode(this.indent), JsonUtf8Encoder.DEFAULT_BUFFER_SIZE); | |
868 } | |
869 return new _JsonEncoderSink(dart.as(sink, StringConversionSink), this[_toE
ncodable$], this.indent); | |
870 } | |
871 bind(stream) { | |
872 return super.bind(stream); | |
873 } | |
874 fuse(other) { | |
875 if (dart.is(other, Utf8Encoder)) { | |
876 return new JsonUtf8Encoder(this.indent, dart.as(this[_toEncodable$], dar
t.functionType(dart.dynamic, [core.Object]))); | |
877 } | |
878 return super.fuse(other); | |
879 } | |
880 } | |
881 dart.defineNamedConstructor(JsonEncoder, 'withIndent'); | |
882 dart.setSignature(JsonEncoder, { | |
883 constructors: () => ({ | |
884 JsonEncoder: [JsonEncoder, [], [dart.functionType(core.Object, [core.Objec
t])]], | |
885 withIndent: [JsonEncoder, [core.String], [dart.functionType(core.Object, [
core.Object])]] | |
886 }), | |
887 methods: () => ({ | |
888 convert: [core.String, [core.Object]], | |
889 startChunkedConversion: [ChunkedConversionSink$(core.Object), [core.Sink$(
core.String)]], | |
890 bind: [async.Stream$(core.String), [async.Stream$(core.Object)]], | |
891 fuse: [Converter$(core.Object, dart.dynamic), [Converter$(core.String, dar
t.dynamic)]] | |
892 }) | |
893 }); | |
894 const _indent = Symbol('_indent'); | |
895 const _bufferSize = Symbol('_bufferSize'); | |
896 class JsonUtf8Encoder extends Converter$(core.Object, core.List$(core.int)) { | |
897 JsonUtf8Encoder(indent, toEncodable, bufferSize) { | |
898 if (indent === void 0) indent = null; | |
899 if (toEncodable === void 0) toEncodable = null; | |
900 if (bufferSize === void 0) bufferSize = JsonUtf8Encoder.DEFAULT_BUFFER_SIZ
E; | |
901 this[_indent] = JsonUtf8Encoder._utf8Encode(indent); | |
902 this[_toEncodable$] = toEncodable; | |
903 this[_bufferSize] = bufferSize; | |
904 super.Converter(); | |
905 } | |
906 static _utf8Encode(string) { | |
907 if (string == null) return null; | |
908 if (dart.notNull(string[dartx.isEmpty])) return typed_data.Uint8List.new(0
); | |
909 checkAscii: { | |
910 for (let i = 0; i < dart.notNull(string[dartx.length]); i++) { | |
911 if (dart.notNull(string[dartx.codeUnitAt](i)) >= 128) break checkAscii
; | |
912 } | |
913 return string[dartx.codeUnits]; | |
914 } | |
915 return UTF8.encode(string); | |
916 } | |
917 convert(object) { | |
918 let bytes = dart.list([], core.List$(core.int)); | |
919 function addChunk(chunk, start, end) { | |
920 if (dart.notNull(start) > 0 || dart.notNull(end) < dart.notNull(chunk[da
rtx.length])) { | |
921 let length = dart.notNull(end) - dart.notNull(start); | |
922 chunk = typed_data.Uint8List.view(chunk[dartx.buffer], dart.notNull(ch
unk[dartx.offsetInBytes]) + dart.notNull(start), length); | |
923 } | |
924 bytes[dartx.add](chunk); | |
925 } | |
926 dart.fn(addChunk, dart.void, [typed_data.Uint8List, core.int, core.int]); | |
927 _JsonUtf8Stringifier.stringify(object, this[_indent], dart.as(this[_toEnco
dable$], dart.functionType(dart.dynamic, [core.Object])), this[_bufferSize], add
Chunk); | |
928 if (bytes[dartx.length] == 1) return bytes[dartx.get](0); | |
929 let length = 0; | |
930 for (let i = 0; i < dart.notNull(bytes[dartx.length]); i++) { | |
931 length = dart.notNull(length) + dart.notNull(bytes[dartx.get](i)[dartx.l
ength]); | |
932 } | |
933 let result = typed_data.Uint8List.new(length); | |
934 for (let i = 0, offset = 0; i < dart.notNull(bytes[dartx.length]); i++) { | |
935 let byteList = bytes[dartx.get](i); | |
936 let end = offset + dart.notNull(byteList[dartx.length]); | |
937 result[dartx.setRange](offset, end, byteList); | |
938 offset = end; | |
939 } | |
940 return result; | |
941 } | |
942 startChunkedConversion(sink) { | |
943 let byteSink = null; | |
944 if (dart.is(sink, ByteConversionSink)) { | |
945 byteSink = sink; | |
946 } else { | |
947 byteSink = ByteConversionSink.from(sink); | |
948 } | |
949 return new _JsonUtf8EncoderSink(byteSink, this[_toEncodable$], this[_inden
t], this[_bufferSize]); | |
950 } | |
951 bind(stream) { | |
952 return super.bind(stream); | |
953 } | |
954 fuse(other) { | |
955 return super.fuse(other); | |
956 } | |
957 } | |
958 dart.setSignature(JsonUtf8Encoder, { | |
959 constructors: () => ({JsonUtf8Encoder: [JsonUtf8Encoder, [], [core.String, d
art.functionType(dart.dynamic, [core.Object]), core.int]]}), | |
960 methods: () => ({ | |
961 convert: [core.List$(core.int), [core.Object]], | |
962 startChunkedConversion: [ChunkedConversionSink$(core.Object), [core.Sink$(
core.List$(core.int))]], | |
963 bind: [async.Stream$(core.List$(core.int)), [async.Stream$(core.Object)]], | |
964 fuse: [Converter$(core.Object, dart.dynamic), [Converter$(core.List$(core.
int), dart.dynamic)]] | |
965 }), | |
966 statics: () => ({_utf8Encode: [core.List$(core.int), [core.String]]}), | |
967 names: ['_utf8Encode'] | |
968 }); | |
969 JsonUtf8Encoder.DEFAULT_BUFFER_SIZE = 256; | |
970 const _isDone = Symbol('_isDone'); | |
971 class _JsonEncoderSink extends ChunkedConversionSink$(core.Object) { | |
972 _JsonEncoderSink(sink, toEncodable, indent) { | |
973 this[_sink] = sink; | |
974 this[_toEncodable$] = toEncodable; | |
975 this[_indent] = indent; | |
976 this[_isDone] = false; | |
977 super.ChunkedConversionSink(); | |
978 } | |
979 add(o) { | |
980 if (dart.notNull(this[_isDone])) { | |
981 dart.throw(new core.StateError("Only one call to add allowed")); | |
982 } | |
983 this[_isDone] = true; | |
984 let stringSink = this[_sink].asStringSink(); | |
985 _JsonStringStringifier.printOn(o, stringSink, dart.as(this[_toEncodable$],
dart.functionType(dart.dynamic, [dart.dynamic])), this[_indent]); | |
986 stringSink.close(); | |
987 } | |
988 close() {} | |
989 } | |
990 dart.setSignature(_JsonEncoderSink, { | |
991 constructors: () => ({_JsonEncoderSink: [_JsonEncoderSink, [StringConversion
Sink, core.Function, core.String]]}), | |
992 methods: () => ({ | |
993 add: [dart.void, [core.Object]], | |
994 close: [dart.void, []] | |
995 }) | |
996 }); | |
997 const _addChunk = Symbol('_addChunk'); | |
998 class _JsonUtf8EncoderSink extends ChunkedConversionSink$(core.Object) { | |
999 _JsonUtf8EncoderSink(sink, toEncodable, indent, bufferSize) { | |
1000 this[_sink] = sink; | |
1001 this[_toEncodable$] = toEncodable; | |
1002 this[_indent] = indent; | |
1003 this[_bufferSize] = bufferSize; | |
1004 this[_isDone] = false; | |
1005 super.ChunkedConversionSink(); | |
1006 } | |
1007 [_addChunk](chunk, start, end) { | |
1008 this[_sink].addSlice(chunk, start, end, false); | |
1009 } | |
1010 add(object) { | |
1011 if (dart.notNull(this[_isDone])) { | |
1012 dart.throw(new core.StateError("Only one call to add allowed")); | |
1013 } | |
1014 this[_isDone] = true; | |
1015 _JsonUtf8Stringifier.stringify(object, this[_indent], dart.as(this[_toEnco
dable$], dart.functionType(dart.dynamic, [core.Object])), this[_bufferSize], dar
t.bind(this, _addChunk)); | |
1016 this[_sink].close(); | |
1017 } | |
1018 close() { | |
1019 if (!dart.notNull(this[_isDone])) { | |
1020 this[_isDone] = true; | |
1021 this[_sink].close(); | |
1022 } | |
1023 } | |
1024 } | |
1025 dart.setSignature(_JsonUtf8EncoderSink, { | |
1026 constructors: () => ({_JsonUtf8EncoderSink: [_JsonUtf8EncoderSink, [ByteConv
ersionSink, core.Function, core.List$(core.int), core.int]]}), | |
1027 methods: () => ({ | |
1028 [_addChunk]: [dart.void, [typed_data.Uint8List, core.int, core.int]], | |
1029 add: [dart.void, [core.Object]], | |
1030 close: [dart.void, []] | |
1031 }) | |
1032 }); | |
1033 class JsonDecoder extends Converter$(core.String, core.Object) { | |
1034 JsonDecoder(reviver) { | |
1035 if (reviver === void 0) reviver = null; | |
1036 this[_reviver] = reviver; | |
1037 super.Converter(); | |
1038 } | |
1039 convert(input) { | |
1040 return _parseJson(input, this[_reviver]); | |
1041 } | |
1042 startChunkedConversion(sink) { | |
1043 return new _JsonDecoderSink(this[_reviver], sink); | |
1044 } | |
1045 bind(stream) { | |
1046 return super.bind(stream); | |
1047 } | |
1048 } | |
1049 dart.setSignature(JsonDecoder, { | |
1050 constructors: () => ({JsonDecoder: [JsonDecoder, [], [dart.functionType(dart
.dynamic, [dart.dynamic, dart.dynamic])]]}), | |
1051 methods: () => ({ | |
1052 convert: [dart.dynamic, [core.String]], | |
1053 startChunkedConversion: [StringConversionSink, [core.Sink$(core.Object)]], | |
1054 bind: [async.Stream$(core.Object), [async.Stream$(core.String)]] | |
1055 }) | |
1056 }); | |
1057 function _parseJson(source, reviver) { | |
1058 if (!(typeof source == 'string')) dart.throw(new core.ArgumentError(source))
; | |
1059 let parsed = null; | |
1060 try { | |
1061 parsed = dart.global.JSON.parse(source); | |
1062 } catch (e) { | |
1063 dart.throw(new core.FormatException(String(e))); | |
1064 } | |
1065 | |
1066 if (reviver == null) { | |
1067 return _convertJsonToDartLazy(parsed); | |
1068 } else { | |
1069 return _convertJsonToDart(parsed, reviver); | |
1070 } | |
1071 } | |
1072 dart.fn(_parseJson, dart.dynamic, [core.String, dart.functionType(dart.dynamic
, [dart.dynamic, dart.dynamic])]); | |
1073 function _defaultToEncodable(object) { | |
1074 return dart.dsend(object, 'toJson'); | |
1075 } | |
1076 dart.fn(_defaultToEncodable, core.Object, [dart.dynamic]); | |
1077 const _seen = Symbol('_seen'); | |
1078 const _checkCycle = Symbol('_checkCycle'); | |
1079 const _removeSeen = Symbol('_removeSeen'); | |
1080 class _JsonStringifier extends core.Object { | |
1081 _JsonStringifier(_toEncodable) { | |
1082 this[_seen] = core.List.new(); | |
1083 this[_toEncodable$] = _toEncodable != null ? _toEncodable : _defaultToEnco
dable; | |
1084 } | |
1085 static hexDigit(x) { | |
1086 return dart.notNull(x) < 10 ? 48 + dart.notNull(x) : 87 + dart.notNull(x); | |
1087 } | |
1088 writeStringContent(s) { | |
1089 let offset = 0; | |
1090 let length = s[dartx.length]; | |
1091 for (let i = 0; i < dart.notNull(length); i++) { | |
1092 let charCode = s[dartx.codeUnitAt](i); | |
1093 if (dart.notNull(charCode) > dart.notNull(_JsonStringifier.BACKSLASH)) c
ontinue; | |
1094 if (dart.notNull(charCode) < 32) { | |
1095 if (i > offset) this.writeStringSlice(s, offset, i); | |
1096 offset = i + 1; | |
1097 this.writeCharCode(_JsonStringifier.BACKSLASH); | |
1098 switch (charCode) { | |
1099 case _JsonStringifier.BACKSPACE: | |
1100 { | |
1101 this.writeCharCode(_JsonStringifier.CHAR_b); | |
1102 break; | |
1103 } | |
1104 case _JsonStringifier.TAB: | |
1105 { | |
1106 this.writeCharCode(_JsonStringifier.CHAR_t); | |
1107 break; | |
1108 } | |
1109 case _JsonStringifier.NEWLINE: | |
1110 { | |
1111 this.writeCharCode(_JsonStringifier.CHAR_n); | |
1112 break; | |
1113 } | |
1114 case _JsonStringifier.FORM_FEED: | |
1115 { | |
1116 this.writeCharCode(_JsonStringifier.CHAR_f); | |
1117 break; | |
1118 } | |
1119 case _JsonStringifier.CARRIAGE_RETURN: | |
1120 { | |
1121 this.writeCharCode(_JsonStringifier.CHAR_r); | |
1122 break; | |
1123 } | |
1124 default: | |
1125 { | |
1126 this.writeCharCode(_JsonStringifier.CHAR_u); | |
1127 this.writeCharCode(_JsonStringifier.CHAR_0); | |
1128 this.writeCharCode(_JsonStringifier.CHAR_0); | |
1129 this.writeCharCode(_JsonStringifier.hexDigit(dart.notNull(charCode
) >> 4 & 15)); | |
1130 this.writeCharCode(_JsonStringifier.hexDigit(dart.notNull(charCode
) & 15)); | |
1131 break; | |
1132 } | |
1133 } | |
1134 } else if (charCode == _JsonStringifier.QUOTE || charCode == _JsonString
ifier.BACKSLASH) { | |
1135 if (i > offset) this.writeStringSlice(s, offset, i); | |
1136 offset = i + 1; | |
1137 this.writeCharCode(_JsonStringifier.BACKSLASH); | |
1138 this.writeCharCode(charCode); | |
1139 } | |
1140 } | |
1141 if (offset == 0) { | |
1142 this.writeString(s); | |
1143 } else if (offset < dart.notNull(length)) { | |
1144 this.writeStringSlice(s, offset, length); | |
1145 } | |
1146 } | |
1147 [_checkCycle](object) { | |
1148 for (let i = 0; i < dart.notNull(this[_seen][dartx.length]); i++) { | |
1149 if (core.identical(object, this[_seen][dartx.get](i))) { | |
1150 dart.throw(new JsonCyclicError(object)); | |
1151 } | |
1152 } | |
1153 this[_seen][dartx.add](object); | |
1154 } | |
1155 [_removeSeen](object) { | |
1156 dart.assert(!dart.notNull(this[_seen][dartx.isEmpty])); | |
1157 dart.assert(core.identical(this[_seen][dartx.last], object)); | |
1158 this[_seen][dartx.removeLast](); | |
1159 } | |
1160 writeObject(object) { | |
1161 if (dart.notNull(this.writeJsonValue(object))) return; | |
1162 this[_checkCycle](object); | |
1163 try { | |
1164 let customJson = dart.dcall(this[_toEncodable$], object); | |
1165 if (!dart.notNull(this.writeJsonValue(customJson))) { | |
1166 dart.throw(new JsonUnsupportedObjectError(object)); | |
1167 } | |
1168 this[_removeSeen](object); | |
1169 } catch (e) { | |
1170 dart.throw(new JsonUnsupportedObjectError(object, {cause: e})); | |
1171 } | |
1172 | |
1173 } | |
1174 writeJsonValue(object) { | |
1175 if (typeof object == 'number') { | |
1176 if (!dart.notNull(object[dartx.isFinite])) return false; | |
1177 this.writeNumber(object); | |
1178 return true; | |
1179 } else if (core.identical(object, true)) { | |
1180 this.writeString('true'); | |
1181 return true; | |
1182 } else if (core.identical(object, false)) { | |
1183 this.writeString('false'); | |
1184 return true; | |
1185 } else if (object == null) { | |
1186 this.writeString('null'); | |
1187 return true; | |
1188 } else if (typeof object == 'string') { | |
1189 this.writeString('"'); | |
1190 this.writeStringContent(object); | |
1191 this.writeString('"'); | |
1192 return true; | |
1193 } else if (dart.is(object, core.List)) { | |
1194 this[_checkCycle](object); | |
1195 this.writeList(object); | |
1196 this[_removeSeen](object); | |
1197 return true; | |
1198 } else if (dart.is(object, core.Map)) { | |
1199 this[_checkCycle](object); | |
1200 this.writeMap(dart.as(object, core.Map$(core.String, core.Object))); | |
1201 this[_removeSeen](object); | |
1202 return true; | |
1203 } else { | |
1204 return false; | |
1205 } | |
1206 } | |
1207 writeList(list) { | |
1208 this.writeString('['); | |
1209 if (dart.notNull(list[dartx.length]) > 0) { | |
1210 this.writeObject(list[dartx.get](0)); | |
1211 for (let i = 1; i < dart.notNull(list[dartx.length]); i++) { | |
1212 this.writeString(','); | |
1213 this.writeObject(list[dartx.get](i)); | |
1214 } | |
1215 } | |
1216 this.writeString(']'); | |
1217 } | |
1218 writeMap(map) { | |
1219 this.writeString('{'); | |
1220 let separator = '"'; | |
1221 map[dartx.forEach](dart.fn((key, value) => { | |
1222 this.writeString(separator); | |
1223 separator = ',"'; | |
1224 this.writeStringContent(key); | |
1225 this.writeString('":'); | |
1226 this.writeObject(value); | |
1227 }, dart.void, [core.String, core.Object])); | |
1228 this.writeString('}'); | |
1229 } | |
1230 } | |
1231 dart.setSignature(_JsonStringifier, { | |
1232 constructors: () => ({_JsonStringifier: [_JsonStringifier, [dart.functionTyp
e(core.Object, [core.Object])]]}), | |
1233 methods: () => ({ | |
1234 writeStringContent: [dart.void, [core.String]], | |
1235 [_checkCycle]: [dart.void, [dart.dynamic]], | |
1236 [_removeSeen]: [dart.void, [dart.dynamic]], | |
1237 writeObject: [dart.void, [dart.dynamic]], | |
1238 writeJsonValue: [core.bool, [dart.dynamic]], | |
1239 writeList: [dart.void, [core.List]], | |
1240 writeMap: [dart.void, [core.Map$(core.String, core.Object)]] | |
1241 }), | |
1242 statics: () => ({hexDigit: [core.int, [core.int]]}), | |
1243 names: ['hexDigit'] | |
1244 }); | |
1245 _JsonStringifier.BACKSPACE = 8; | |
1246 _JsonStringifier.TAB = 9; | |
1247 _JsonStringifier.NEWLINE = 10; | |
1248 _JsonStringifier.CARRIAGE_RETURN = 13; | |
1249 _JsonStringifier.FORM_FEED = 12; | |
1250 _JsonStringifier.QUOTE = 34; | |
1251 _JsonStringifier.CHAR_0 = 48; | |
1252 _JsonStringifier.BACKSLASH = 92; | |
1253 _JsonStringifier.CHAR_b = 98; | |
1254 _JsonStringifier.CHAR_f = 102; | |
1255 _JsonStringifier.CHAR_n = 110; | |
1256 _JsonStringifier.CHAR_r = 114; | |
1257 _JsonStringifier.CHAR_t = 116; | |
1258 _JsonStringifier.CHAR_u = 117; | |
1259 const _indentLevel = Symbol('_indentLevel'); | |
1260 class _JsonPrettyPrintMixin extends core.Object { | |
1261 _JsonPrettyPrintMixin() { | |
1262 this[_indentLevel] = 0; | |
1263 } | |
1264 writeList(list) { | |
1265 if (dart.notNull(list[dartx.isEmpty])) { | |
1266 this.writeString('[]'); | |
1267 } else { | |
1268 this.writeString('[\n'); | |
1269 this[_indentLevel] = dart.notNull(this[_indentLevel]) + 1; | |
1270 this.writeIndentation(this[_indentLevel]); | |
1271 this.writeObject(list[dartx.get](0)); | |
1272 for (let i = 1; i < dart.notNull(list[dartx.length]); i++) { | |
1273 this.writeString(',\n'); | |
1274 this.writeIndentation(this[_indentLevel]); | |
1275 this.writeObject(list[dartx.get](i)); | |
1276 } | |
1277 this.writeString('\n'); | |
1278 this[_indentLevel] = dart.notNull(this[_indentLevel]) - 1; | |
1279 this.writeIndentation(this[_indentLevel]); | |
1280 this.writeString(']'); | |
1281 } | |
1282 } | |
1283 writeMap(map) { | |
1284 if (dart.notNull(map[dartx.isEmpty])) { | |
1285 this.writeString('{}'); | |
1286 } else { | |
1287 this.writeString('{\n'); | |
1288 this[_indentLevel] = dart.notNull(this[_indentLevel]) + 1; | |
1289 let first = true; | |
1290 map[dartx.forEach](dart.fn((key, value) => { | |
1291 if (!first) { | |
1292 this.writeString(",\n"); | |
1293 } | |
1294 this.writeIndentation(this[_indentLevel]); | |
1295 this.writeString('"'); | |
1296 this.writeStringContent(key); | |
1297 this.writeString('": '); | |
1298 this.writeObject(value); | |
1299 first = false; | |
1300 }, dart.void, [core.String, core.Object])); | |
1301 this.writeString('\n'); | |
1302 this[_indentLevel] = dart.notNull(this[_indentLevel]) - 1; | |
1303 this.writeIndentation(this[_indentLevel]); | |
1304 this.writeString('}'); | |
1305 } | |
1306 } | |
1307 } | |
1308 _JsonPrettyPrintMixin[dart.implements] = () => [_JsonStringifier]; | |
1309 dart.setSignature(_JsonPrettyPrintMixin, { | |
1310 methods: () => ({ | |
1311 writeList: [dart.void, [core.List]], | |
1312 writeMap: [dart.void, [core.Map]] | |
1313 }) | |
1314 }); | |
1315 class _JsonStringStringifier extends _JsonStringifier { | |
1316 _JsonStringStringifier(sink, _toEncodable) { | |
1317 this[_sink] = sink; | |
1318 super._JsonStringifier(dart.as(_toEncodable, dart.functionType(core.Object
, [core.Object]))); | |
1319 } | |
1320 static stringify(object, toEncodable, indent) { | |
1321 let output = new core.StringBuffer(); | |
1322 _JsonStringStringifier.printOn(object, output, toEncodable, indent); | |
1323 return output.toString(); | |
1324 } | |
1325 static printOn(object, output, toEncodable, indent) { | |
1326 let stringifier = null; | |
1327 if (indent == null) { | |
1328 stringifier = new _JsonStringStringifier(output, toEncodable); | |
1329 } else { | |
1330 stringifier = new _JsonStringStringifierPretty(output, toEncodable, inde
nt); | |
1331 } | |
1332 dart.dsend(stringifier, 'writeObject', object); | |
1333 } | |
1334 writeNumber(number) { | |
1335 this[_sink].write(dart.toString(number)); | |
1336 } | |
1337 writeString(string) { | |
1338 this[_sink].write(string); | |
1339 } | |
1340 writeStringSlice(string, start, end) { | |
1341 this[_sink].write(string[dartx.substring](start, end)); | |
1342 } | |
1343 writeCharCode(charCode) { | |
1344 this[_sink].writeCharCode(charCode); | |
1345 } | |
1346 } | |
1347 dart.setSignature(_JsonStringStringifier, { | |
1348 constructors: () => ({_JsonStringStringifier: [_JsonStringStringifier, [core
.StringSink, dart.dynamic]]}), | |
1349 methods: () => ({ | |
1350 writeNumber: [dart.void, [core.num]], | |
1351 writeString: [dart.void, [core.String]], | |
1352 writeStringSlice: [dart.void, [core.String, core.int, core.int]], | |
1353 writeCharCode: [dart.void, [core.int]] | |
1354 }), | |
1355 statics: () => ({ | |
1356 stringify: [core.String, [dart.dynamic, dart.functionType(dart.dynamic, [d
art.dynamic]), core.String]], | |
1357 printOn: [dart.void, [dart.dynamic, core.StringSink, dart.functionType(dar
t.dynamic, [dart.dynamic]), core.String]] | |
1358 }), | |
1359 names: ['stringify', 'printOn'] | |
1360 }); | |
1361 class _JsonStringStringifierPretty extends dart.mixin(_JsonStringStringifier,
_JsonPrettyPrintMixin) { | |
1362 _JsonStringStringifierPretty(sink, toEncodable, indent) { | |
1363 this[_indent] = indent; | |
1364 super._JsonStringStringifier(sink, toEncodable); | |
1365 } | |
1366 writeIndentation(count) { | |
1367 for (let i = 0; i < dart.notNull(count); i++) | |
1368 this.writeString(this[_indent]); | |
1369 } | |
1370 } | |
1371 dart.setSignature(_JsonStringStringifierPretty, { | |
1372 constructors: () => ({_JsonStringStringifierPretty: [_JsonStringStringifierP
retty, [core.StringSink, core.Function, core.String]]}), | |
1373 methods: () => ({writeIndentation: [dart.void, [core.int]]}) | |
1374 }); | |
1375 class _JsonUtf8Stringifier extends _JsonStringifier { | |
1376 _JsonUtf8Stringifier(toEncodable, bufferSize, addChunk) { | |
1377 this.addChunk = addChunk; | |
1378 this.bufferSize = bufferSize; | |
1379 this.buffer = typed_data.Uint8List.new(bufferSize); | |
1380 this.index = 0; | |
1381 super._JsonStringifier(dart.as(toEncodable, dart.functionType(core.Object,
[core.Object]))); | |
1382 } | |
1383 static stringify(object, indent, toEncodableFunction, bufferSize, addChunk)
{ | |
1384 let stringifier = null; | |
1385 if (indent != null) { | |
1386 stringifier = new _JsonUtf8StringifierPretty(toEncodableFunction, indent
, bufferSize, addChunk); | |
1387 } else { | |
1388 stringifier = new _JsonUtf8Stringifier(toEncodableFunction, bufferSize,
addChunk); | |
1389 } | |
1390 stringifier.writeObject(object); | |
1391 stringifier.flush(); | |
1392 } | |
1393 flush() { | |
1394 if (dart.notNull(this.index) > 0) { | |
1395 dart.dcall(this.addChunk, this.buffer, 0, this.index); | |
1396 } | |
1397 this.buffer = null; | |
1398 this.index = 0; | |
1399 } | |
1400 writeNumber(number) { | |
1401 this.writeAsciiString(dart.toString(number)); | |
1402 } | |
1403 writeAsciiString(string) { | |
1404 for (let i = 0; i < dart.notNull(string[dartx.length]); i++) { | |
1405 let char = string[dartx.codeUnitAt](i); | |
1406 dart.assert(dart.notNull(char) <= 127); | |
1407 this.writeByte(char); | |
1408 } | |
1409 } | |
1410 writeString(string) { | |
1411 this.writeStringSlice(string, 0, string[dartx.length]); | |
1412 } | |
1413 writeStringSlice(string, start, end) { | |
1414 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(
i) + 1) { | |
1415 let char = string[dartx.codeUnitAt](i); | |
1416 if (dart.notNull(char) <= 127) { | |
1417 this.writeByte(char); | |
1418 } else { | |
1419 if ((dart.notNull(char) & 64512) == 55296 && dart.notNull(i) + 1 < dar
t.notNull(end)) { | |
1420 let nextChar = string[dartx.codeUnitAt](dart.notNull(i) + 1); | |
1421 if ((dart.notNull(nextChar) & 64512) == 56320) { | |
1422 char = 65536 + ((dart.notNull(char) & 1023) << 10) + (dart.notNull
(nextChar) & 1023); | |
1423 this.writeFourByteCharCode(char); | |
1424 i = dart.notNull(i) + 1; | |
1425 continue; | |
1426 } | |
1427 } | |
1428 this.writeMultiByteCharCode(char); | |
1429 } | |
1430 } | |
1431 } | |
1432 writeCharCode(charCode) { | |
1433 if (dart.notNull(charCode) <= 127) { | |
1434 this.writeByte(charCode); | |
1435 return; | |
1436 } | |
1437 this.writeMultiByteCharCode(charCode); | |
1438 } | |
1439 writeMultiByteCharCode(charCode) { | |
1440 if (dart.notNull(charCode) <= 2047) { | |
1441 this.writeByte(192 | dart.notNull(charCode) >> 6); | |
1442 this.writeByte(128 | dart.notNull(charCode) & 63); | |
1443 return; | |
1444 } | |
1445 if (dart.notNull(charCode) <= 65535) { | |
1446 this.writeByte(224 | dart.notNull(charCode) >> 12); | |
1447 this.writeByte(128 | dart.notNull(charCode) >> 6 & 63); | |
1448 this.writeByte(128 | dart.notNull(charCode) & 63); | |
1449 return; | |
1450 } | |
1451 this.writeFourByteCharCode(charCode); | |
1452 } | |
1453 writeFourByteCharCode(charCode) { | |
1454 dart.assert(dart.notNull(charCode) <= 1114111); | |
1455 this.writeByte(240 | dart.notNull(charCode) >> 18); | |
1456 this.writeByte(128 | dart.notNull(charCode) >> 12 & 63); | |
1457 this.writeByte(128 | dart.notNull(charCode) >> 6 & 63); | |
1458 this.writeByte(128 | dart.notNull(charCode) & 63); | |
1459 } | |
1460 writeByte(byte) { | |
1461 dart.assert(dart.notNull(byte) <= 255); | |
1462 if (this.index == this.buffer[dartx.length]) { | |
1463 dart.dcall(this.addChunk, this.buffer, 0, this.index); | |
1464 this.buffer = typed_data.Uint8List.new(this.bufferSize); | |
1465 this.index = 0; | |
1466 } | |
1467 this.buffer[dartx.set]((() => { | |
1468 let x = this.index; | |
1469 this.index = dart.notNull(x) + 1; | |
1470 return x; | |
1471 })(), byte); | |
1472 } | |
1473 } | |
1474 dart.setSignature(_JsonUtf8Stringifier, { | |
1475 constructors: () => ({_JsonUtf8Stringifier: [_JsonUtf8Stringifier, [dart.dyn
amic, core.int, core.Function]]}), | |
1476 methods: () => ({ | |
1477 flush: [dart.void, []], | |
1478 writeNumber: [dart.void, [core.num]], | |
1479 writeAsciiString: [dart.void, [core.String]], | |
1480 writeString: [dart.void, [core.String]], | |
1481 writeStringSlice: [dart.void, [core.String, core.int, core.int]], | |
1482 writeCharCode: [dart.void, [core.int]], | |
1483 writeMultiByteCharCode: [dart.void, [core.int]], | |
1484 writeFourByteCharCode: [dart.void, [core.int]], | |
1485 writeByte: [dart.void, [core.int]] | |
1486 }), | |
1487 statics: () => ({stringify: [dart.void, [core.Object, core.List$(core.int),
dart.functionType(dart.dynamic, [core.Object]), core.int, dart.functionType(dart
.void, [typed_data.Uint8List, core.int, core.int])]]}), | |
1488 names: ['stringify'] | |
1489 }); | |
1490 class _JsonUtf8StringifierPretty extends dart.mixin(_JsonUtf8Stringifier, _Jso
nPrettyPrintMixin) { | |
1491 _JsonUtf8StringifierPretty(toEncodableFunction, indent, bufferSize, addChunk
) { | |
1492 this.indent = indent; | |
1493 super._JsonUtf8Stringifier(toEncodableFunction, dart.as(bufferSize, core.i
nt), dart.as(addChunk, core.Function)); | |
1494 } | |
1495 writeIndentation(count) { | |
1496 let indent = this.indent; | |
1497 let indentLength = indent[dartx.length]; | |
1498 if (indentLength == 1) { | |
1499 let char = indent[dartx.get](0); | |
1500 while (dart.notNull(count) > 0) { | |
1501 this.writeByte(char); | |
1502 count = dart.notNull(count) - 1; | |
1503 } | |
1504 return; | |
1505 } | |
1506 while (dart.notNull(count) > 0) { | |
1507 count = dart.notNull(count) - 1; | |
1508 let end = dart.notNull(this.index) + dart.notNull(indentLength); | |
1509 if (end <= dart.notNull(this.buffer[dartx.length])) { | |
1510 this.buffer[dartx.setRange](this.index, end, indent); | |
1511 this.index = end; | |
1512 } else { | |
1513 for (let i = 0; i < dart.notNull(indentLength); i++) { | |
1514 this.writeByte(indent[dartx.get](i)); | |
1515 } | |
1516 } | |
1517 } | |
1518 } | |
1519 } | |
1520 dart.setSignature(_JsonUtf8StringifierPretty, { | |
1521 constructors: () => ({_JsonUtf8StringifierPretty: [_JsonUtf8StringifierPrett
y, [dart.dynamic, core.List$(core.int), dart.dynamic, dart.dynamic]]}), | |
1522 methods: () => ({writeIndentation: [dart.void, [core.int]]}) | |
1523 }); | |
1524 class Latin1Codec extends Encoding { | |
1525 Latin1Codec(opts) { | |
1526 let allowInvalid = opts && 'allowInvalid' in opts ? opts.allowInvalid : fa
lse; | |
1527 this[_allowInvalid] = allowInvalid; | |
1528 super.Encoding(); | |
1529 } | |
1530 get name() { | |
1531 return "iso-8859-1"; | |
1532 } | |
1533 decode(bytes, opts) { | |
1534 let allowInvalid = opts && 'allowInvalid' in opts ? opts.allowInvalid : nu
ll; | |
1535 if (allowInvalid == null) allowInvalid = this[_allowInvalid]; | |
1536 if (dart.notNull(allowInvalid)) { | |
1537 return dart.const(new Latin1Decoder({allowInvalid: true})).convert(bytes
); | |
1538 } else { | |
1539 return dart.const(new Latin1Decoder({allowInvalid: false})).convert(byte
s); | |
1540 } | |
1541 } | |
1542 get encoder() { | |
1543 return dart.const(new Latin1Encoder()); | |
1544 } | |
1545 get decoder() { | |
1546 return dart.notNull(this[_allowInvalid]) ? dart.const(new Latin1Decoder({a
llowInvalid: true})) : dart.const(new Latin1Decoder({allowInvalid: false})); | |
1547 } | |
1548 } | |
1549 dart.setSignature(Latin1Codec, { | |
1550 constructors: () => ({Latin1Codec: [Latin1Codec, [], {allowInvalid: core.boo
l}]}), | |
1551 methods: () => ({decode: [core.String, [core.List$(core.int)], {allowInvalid
: core.bool}]}) | |
1552 }); | |
1553 const LATIN1 = dart.const(new Latin1Codec()); | |
1554 const _LATIN1_MASK = 255; | |
1555 class Latin1Encoder extends _UnicodeSubsetEncoder { | |
1556 Latin1Encoder() { | |
1557 super._UnicodeSubsetEncoder(_LATIN1_MASK); | |
1558 } | |
1559 } | |
1560 dart.setSignature(Latin1Encoder, { | |
1561 constructors: () => ({Latin1Encoder: [Latin1Encoder, []]}) | |
1562 }); | |
1563 class Latin1Decoder extends _UnicodeSubsetDecoder { | |
1564 Latin1Decoder(opts) { | |
1565 let allowInvalid = opts && 'allowInvalid' in opts ? opts.allowInvalid : fa
lse; | |
1566 super._UnicodeSubsetDecoder(allowInvalid, _LATIN1_MASK); | |
1567 } | |
1568 startChunkedConversion(sink) { | |
1569 let stringSink = null; | |
1570 if (dart.is(sink, StringConversionSink)) { | |
1571 stringSink = sink; | |
1572 } else { | |
1573 stringSink = StringConversionSink.from(sink); | |
1574 } | |
1575 if (!dart.notNull(this[_allowInvalid])) return new _Latin1DecoderSink(stri
ngSink); | |
1576 return new _Latin1AllowInvalidDecoderSink(stringSink); | |
1577 } | |
1578 } | |
1579 dart.setSignature(Latin1Decoder, { | |
1580 constructors: () => ({Latin1Decoder: [Latin1Decoder, [], {allowInvalid: core
.bool}]}), | |
1581 methods: () => ({startChunkedConversion: [ByteConversionSink, [core.Sink$(co
re.String)]]}) | |
1582 }); | |
1583 const _addSliceToSink = Symbol('_addSliceToSink'); | |
1584 class _Latin1DecoderSink extends ByteConversionSinkBase { | |
1585 _Latin1DecoderSink(sink) { | |
1586 this[_sink] = sink; | |
1587 } | |
1588 close() { | |
1589 this[_sink].close(); | |
1590 } | |
1591 add(source) { | |
1592 this.addSlice(source, 0, source[dartx.length], false); | |
1593 } | |
1594 [_addSliceToSink](source, start, end, isLast) { | |
1595 this[_sink].add(core.String.fromCharCodes(source, start, end)); | |
1596 if (dart.notNull(isLast)) this.close(); | |
1597 } | |
1598 addSlice(source, start, end, isLast) { | |
1599 core.RangeError.checkValidRange(start, end, source[dartx.length]); | |
1600 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(
i) + 1) { | |
1601 let char = source[dartx.get](i); | |
1602 if (dart.notNull(char) > dart.notNull(_LATIN1_MASK) || dart.notNull(char
) < 0) { | |
1603 dart.throw(new core.FormatException("Source contains non-Latin-1 chara
cters.")); | |
1604 } | |
1605 } | |
1606 if (dart.notNull(start) < dart.notNull(end)) { | |
1607 this[_addSliceToSink](source, start, end, isLast); | |
1608 } | |
1609 if (dart.notNull(isLast)) { | |
1610 this.close(); | |
1611 } | |
1612 } | |
1613 } | |
1614 dart.setSignature(_Latin1DecoderSink, { | |
1615 constructors: () => ({_Latin1DecoderSink: [_Latin1DecoderSink, [StringConver
sionSink]]}), | |
1616 methods: () => ({ | |
1617 close: [dart.void, []], | |
1618 add: [dart.void, [core.List$(core.int)]], | |
1619 [_addSliceToSink]: [dart.void, [core.List$(core.int), core.int, core.int,
core.bool]] | |
1620 }) | |
1621 }); | |
1622 class _Latin1AllowInvalidDecoderSink extends _Latin1DecoderSink { | |
1623 _Latin1AllowInvalidDecoderSink(sink) { | |
1624 super._Latin1DecoderSink(sink); | |
1625 } | |
1626 addSlice(source, start, end, isLast) { | |
1627 core.RangeError.checkValidRange(start, end, source[dartx.length]); | |
1628 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(
i) + 1) { | |
1629 let char = source[dartx.get](i); | |
1630 if (dart.notNull(char) > dart.notNull(_LATIN1_MASK) || dart.notNull(char
) < 0) { | |
1631 if (dart.notNull(i) > dart.notNull(start)) this[_addSliceToSink](sourc
e, start, i, false); | |
1632 this[_addSliceToSink](dart.const(dart.list([65533], core.int)), 0, 1,
false); | |
1633 start = dart.notNull(i) + 1; | |
1634 } | |
1635 } | |
1636 if (dart.notNull(start) < dart.notNull(end)) { | |
1637 this[_addSliceToSink](source, start, end, isLast); | |
1638 } | |
1639 if (dart.notNull(isLast)) { | |
1640 this.close(); | |
1641 } | |
1642 } | |
1643 } | |
1644 dart.setSignature(_Latin1AllowInvalidDecoderSink, { | |
1645 constructors: () => ({_Latin1AllowInvalidDecoderSink: [_Latin1AllowInvalidDe
coderSink, [StringConversionSink]]}) | |
1646 }); | |
1647 class LineSplitter extends Converter$(core.String, core.List$(core.String)) { | |
1648 LineSplitter() { | |
1649 super.Converter(); | |
1650 } | |
1651 convert(data) { | |
1652 let lines = core.List$(core.String).new(); | |
1653 _LineSplitterSink._addSlice(data, 0, data[dartx.length], true, dart.bind(l
ines, dartx.add)); | |
1654 return lines; | |
1655 } | |
1656 startChunkedConversion(sink) { | |
1657 if (!dart.is(sink, StringConversionSink)) { | |
1658 sink = StringConversionSink.from(dart.as(sink, core.Sink$(core.String)))
; | |
1659 } | |
1660 return new _LineSplitterSink(dart.as(sink, StringConversionSink)); | |
1661 } | |
1662 } | |
1663 dart.setSignature(LineSplitter, { | |
1664 constructors: () => ({LineSplitter: [LineSplitter, []]}), | |
1665 methods: () => ({ | |
1666 convert: [core.List$(core.String), [core.String]], | |
1667 startChunkedConversion: [StringConversionSink, [core.Sink]] | |
1668 }) | |
1669 }); | |
1670 const _carry = Symbol('_carry'); | |
1671 class _LineSplitterSink extends StringConversionSinkBase { | |
1672 _LineSplitterSink(sink) { | |
1673 this[_sink] = sink; | |
1674 this[_carry] = null; | |
1675 } | |
1676 addSlice(chunk, start, end, isLast) { | |
1677 if (this[_carry] != null) { | |
1678 chunk = dart.notNull(this[_carry]) + dart.notNull(chunk[dartx.substring]
(start, end)); | |
1679 start = 0; | |
1680 end = chunk[dartx.length]; | |
1681 this[_carry] = null; | |
1682 } | |
1683 this[_carry] = _LineSplitterSink._addSlice(chunk, start, end, isLast, dart
.bind(this[_sink], 'add')); | |
1684 if (dart.notNull(isLast)) this[_sink].close(); | |
1685 } | |
1686 close() { | |
1687 this.addSlice('', 0, 0, true); | |
1688 } | |
1689 static _addSlice(chunk, start, end, isLast, adder) { | |
1690 let pos = start; | |
1691 while (dart.notNull(pos) < dart.notNull(end)) { | |
1692 let skip = 0; | |
1693 let char = chunk[dartx.codeUnitAt](pos); | |
1694 if (char == _LineSplitterSink._LF) { | |
1695 skip = 1; | |
1696 } else if (char == _LineSplitterSink._CR) { | |
1697 skip = 1; | |
1698 if (dart.notNull(pos) + 1 < dart.notNull(end)) { | |
1699 if (chunk[dartx.codeUnitAt](dart.notNull(pos) + 1) == _LineSplitterS
ink._LF) { | |
1700 skip = 2; | |
1701 } | |
1702 } else if (!dart.notNull(isLast)) { | |
1703 return chunk[dartx.substring](start, end); | |
1704 } | |
1705 } | |
1706 if (skip > 0) { | |
1707 adder(chunk[dartx.substring](start, pos)); | |
1708 start = pos = dart.notNull(pos) + skip; | |
1709 } else { | |
1710 pos = dart.notNull(pos) + 1; | |
1711 } | |
1712 } | |
1713 if (pos != start) { | |
1714 let carry = chunk[dartx.substring](start, pos); | |
1715 if (dart.notNull(isLast)) { | |
1716 adder(carry); | |
1717 } else { | |
1718 return carry; | |
1719 } | |
1720 } | |
1721 return null; | |
1722 } | |
1723 } | |
1724 dart.setSignature(_LineSplitterSink, { | |
1725 constructors: () => ({_LineSplitterSink: [_LineSplitterSink, [StringConversi
onSink]]}), | |
1726 methods: () => ({ | |
1727 addSlice: [dart.void, [core.String, core.int, core.int, core.bool]], | |
1728 close: [dart.void, []] | |
1729 }), | |
1730 statics: () => ({_addSlice: [core.String, [core.String, core.int, core.int,
core.bool, dart.functionType(dart.void, [core.String])]]}), | |
1731 names: ['_addSlice'] | |
1732 }); | |
1733 _LineSplitterSink._LF = 10; | |
1734 _LineSplitterSink._CR = 13; | |
1735 class StringConversionSink extends ChunkedConversionSink$(core.String) { | |
1736 StringConversionSink() { | |
1737 super.ChunkedConversionSink(); | |
1738 } | |
1739 static withCallback(callback) { | |
1740 return new _StringCallbackSink(callback); | |
1741 } | |
1742 static from(sink) { | |
1743 return new _StringAdapterSink(sink); | |
1744 } | |
1745 static fromStringSink(sink) { | |
1746 return new _StringSinkConversionSink(sink); | |
1747 } | |
1748 } | |
1749 dart.setSignature(StringConversionSink, { | |
1750 constructors: () => ({ | |
1751 StringConversionSink: [StringConversionSink, []], | |
1752 withCallback: [StringConversionSink, [dart.functionType(dart.void, [core.S
tring])]], | |
1753 from: [StringConversionSink, [core.Sink$(core.String)]], | |
1754 fromStringSink: [StringConversionSink, [core.StringSink]] | |
1755 }) | |
1756 }); | |
1757 class ClosableStringSink extends core.StringSink { | |
1758 static fromStringSink(sink, onClose) { | |
1759 return new _ClosableStringSink(sink, onClose); | |
1760 } | |
1761 } | |
1762 dart.setSignature(ClosableStringSink, { | |
1763 constructors: () => ({fromStringSink: [ClosableStringSink, [core.StringSink,
dart.functionType(dart.void, [])]]}) | |
1764 }); | |
1765 const _StringSinkCloseCallback = dart.typedef('_StringSinkCloseCallback', () =
> dart.functionType(dart.void, [])); | |
1766 class _ClosableStringSink extends core.Object { | |
1767 _ClosableStringSink(sink, callback) { | |
1768 this[_sink] = sink; | |
1769 this[_callback] = callback; | |
1770 } | |
1771 close() { | |
1772 return this[_callback](); | |
1773 } | |
1774 writeCharCode(charCode) { | |
1775 return this[_sink].writeCharCode(charCode); | |
1776 } | |
1777 write(o) { | |
1778 return this[_sink].write(o); | |
1779 } | |
1780 writeln(o) { | |
1781 if (o === void 0) o = ""; | |
1782 return this[_sink].writeln(o); | |
1783 } | |
1784 writeAll(objects, separator) { | |
1785 if (separator === void 0) separator = ""; | |
1786 return this[_sink].writeAll(objects, separator); | |
1787 } | |
1788 } | |
1789 _ClosableStringSink[dart.implements] = () => [ClosableStringSink]; | |
1790 dart.setSignature(_ClosableStringSink, { | |
1791 constructors: () => ({_ClosableStringSink: [_ClosableStringSink, [core.Strin
gSink, _StringSinkCloseCallback]]}), | |
1792 methods: () => ({ | |
1793 close: [dart.void, []], | |
1794 writeCharCode: [dart.void, [core.int]], | |
1795 write: [dart.void, [core.Object]], | |
1796 writeln: [dart.void, [], [core.Object]], | |
1797 writeAll: [dart.void, [core.Iterable], [core.String]] | |
1798 }) | |
1799 }); | |
1800 const _flush = Symbol('_flush'); | |
1801 class _StringConversionSinkAsStringSinkAdapter extends core.Object { | |
1802 _StringConversionSinkAsStringSinkAdapter(chunkedSink) { | |
1803 this[_chunkedSink] = chunkedSink; | |
1804 this[_buffer] = new core.StringBuffer(); | |
1805 } | |
1806 close() { | |
1807 if (dart.notNull(this[_buffer].isNotEmpty)) this[_flush](); | |
1808 this[_chunkedSink].close(); | |
1809 } | |
1810 writeCharCode(charCode) { | |
1811 this[_buffer].writeCharCode(charCode); | |
1812 if (dart.notNull(this[_buffer].length) > dart.notNull(_StringConversionSin
kAsStringSinkAdapter._MIN_STRING_SIZE)) this[_flush](); | |
1813 } | |
1814 write(o) { | |
1815 if (dart.notNull(this[_buffer].isNotEmpty)) this[_flush](); | |
1816 let str = dart.toString(o); | |
1817 this[_chunkedSink].add(dart.toString(o)); | |
1818 } | |
1819 writeln(o) { | |
1820 if (o === void 0) o = ""; | |
1821 this[_buffer].writeln(o); | |
1822 if (dart.notNull(this[_buffer].length) > dart.notNull(_StringConversionSin
kAsStringSinkAdapter._MIN_STRING_SIZE)) this[_flush](); | |
1823 } | |
1824 writeAll(objects, separator) { | |
1825 if (separator === void 0) separator = ""; | |
1826 if (dart.notNull(this[_buffer].isNotEmpty)) this[_flush](); | |
1827 let iterator = objects[dartx.iterator]; | |
1828 if (!dart.notNull(iterator.moveNext())) return; | |
1829 if (dart.notNull(separator[dartx.isEmpty])) { | |
1830 do { | |
1831 this[_chunkedSink].add(dart.toString(iterator.current)); | |
1832 } while (dart.notNull(iterator.moveNext())); | |
1833 } else { | |
1834 this[_chunkedSink].add(dart.toString(iterator.current)); | |
1835 while (dart.notNull(iterator.moveNext())) { | |
1836 this.write(separator); | |
1837 this[_chunkedSink].add(dart.toString(iterator.current)); | |
1838 } | |
1839 } | |
1840 } | |
1841 [_flush]() { | |
1842 let accumulated = dart.toString(this[_buffer]); | |
1843 this[_buffer].clear(); | |
1844 this[_chunkedSink].add(accumulated); | |
1845 } | |
1846 } | |
1847 _StringConversionSinkAsStringSinkAdapter[dart.implements] = () => [ClosableStr
ingSink]; | |
1848 dart.setSignature(_StringConversionSinkAsStringSinkAdapter, { | |
1849 constructors: () => ({_StringConversionSinkAsStringSinkAdapter: [_StringConv
ersionSinkAsStringSinkAdapter, [StringConversionSink]]}), | |
1850 methods: () => ({ | |
1851 close: [dart.void, []], | |
1852 writeCharCode: [dart.void, [core.int]], | |
1853 write: [dart.void, [core.Object]], | |
1854 writeln: [dart.void, [], [core.Object]], | |
1855 writeAll: [dart.void, [core.Iterable], [core.String]], | |
1856 [_flush]: [dart.void, []] | |
1857 }) | |
1858 }); | |
1859 _StringConversionSinkAsStringSinkAdapter._MIN_STRING_SIZE = 16; | |
1860 const _stringSink = Symbol('_stringSink'); | |
1861 class _StringSinkConversionSink extends StringConversionSinkBase { | |
1862 _StringSinkConversionSink(stringSink) { | |
1863 this[_stringSink] = stringSink; | |
1864 } | |
1865 close() {} | |
1866 addSlice(str, start, end, isLast) { | |
1867 if (start != 0 || end != str[dartx.length]) { | |
1868 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNul
l(i) + 1) { | |
1869 this[_stringSink].writeCharCode(str[dartx.codeUnitAt](i)); | |
1870 } | |
1871 } else { | |
1872 this[_stringSink].write(str); | |
1873 } | |
1874 if (dart.notNull(isLast)) this.close(); | |
1875 } | |
1876 add(str) { | |
1877 return this[_stringSink].write(str); | |
1878 } | |
1879 asUtf8Sink(allowMalformed) { | |
1880 return new _Utf8StringSinkAdapter(this, this[_stringSink], allowMalformed)
; | |
1881 } | |
1882 asStringSink() { | |
1883 return ClosableStringSink.fromStringSink(this[_stringSink], dart.bind(this
, 'close')); | |
1884 } | |
1885 } | |
1886 dart.setSignature(_StringSinkConversionSink, { | |
1887 constructors: () => ({_StringSinkConversionSink: [_StringSinkConversionSink,
[core.StringSink]]}), | |
1888 methods: () => ({ | |
1889 close: [dart.void, []], | |
1890 addSlice: [dart.void, [core.String, core.int, core.int, core.bool]] | |
1891 }) | |
1892 }); | |
1893 class _StringCallbackSink extends _StringSinkConversionSink { | |
1894 _StringCallbackSink(callback) { | |
1895 this[_callback] = callback; | |
1896 super._StringSinkConversionSink(new core.StringBuffer()); | |
1897 } | |
1898 close() { | |
1899 let buffer = dart.as(this[_stringSink], core.StringBuffer); | |
1900 let accumulated = dart.toString(buffer); | |
1901 buffer.clear(); | |
1902 this[_callback](accumulated); | |
1903 } | |
1904 asUtf8Sink(allowMalformed) { | |
1905 return new _Utf8StringSinkAdapter(this, this[_stringSink], allowMalformed)
; | |
1906 } | |
1907 } | |
1908 dart.setSignature(_StringCallbackSink, { | |
1909 constructors: () => ({_StringCallbackSink: [_StringCallbackSink, [_ChunkedCo
nversionCallback$(core.String)]]}) | |
1910 }); | |
1911 class _StringAdapterSink extends StringConversionSinkBase { | |
1912 _StringAdapterSink(sink) { | |
1913 this[_sink] = sink; | |
1914 } | |
1915 add(str) { | |
1916 return this[_sink].add(str); | |
1917 } | |
1918 addSlice(str, start, end, isLast) { | |
1919 if (start == 0 && end == str[dartx.length]) { | |
1920 this.add(str); | |
1921 } else { | |
1922 this.add(str[dartx.substring](start, end)); | |
1923 } | |
1924 if (dart.notNull(isLast)) this.close(); | |
1925 } | |
1926 close() { | |
1927 return this[_sink].close(); | |
1928 } | |
1929 } | |
1930 dart.setSignature(_StringAdapterSink, { | |
1931 constructors: () => ({_StringAdapterSink: [_StringAdapterSink, [core.Sink$(c
ore.String)]]}), | |
1932 methods: () => ({ | |
1933 addSlice: [dart.void, [core.String, core.int, core.int, core.bool]], | |
1934 close: [dart.void, []] | |
1935 }) | |
1936 }); | |
1937 const _decoder = Symbol('_decoder'); | |
1938 class _Utf8StringSinkAdapter extends ByteConversionSink { | |
1939 _Utf8StringSinkAdapter(sink, stringSink, allowMalformed) { | |
1940 this[_sink] = sink; | |
1941 this[_decoder] = new _Utf8Decoder(stringSink, allowMalformed); | |
1942 super.ByteConversionSink(); | |
1943 } | |
1944 close() { | |
1945 this[_decoder].close(); | |
1946 if (this[_sink] != null) this[_sink].close(); | |
1947 } | |
1948 add(chunk) { | |
1949 this.addSlice(chunk, 0, chunk[dartx.length], false); | |
1950 } | |
1951 addSlice(codeUnits, startIndex, endIndex, isLast) { | |
1952 this[_decoder].convert(codeUnits, startIndex, endIndex); | |
1953 if (dart.notNull(isLast)) this.close(); | |
1954 } | |
1955 } | |
1956 dart.setSignature(_Utf8StringSinkAdapter, { | |
1957 constructors: () => ({_Utf8StringSinkAdapter: [_Utf8StringSinkAdapter, [core
.Sink, core.StringSink, core.bool]]}), | |
1958 methods: () => ({ | |
1959 close: [dart.void, []], | |
1960 add: [dart.void, [core.List$(core.int)]], | |
1961 addSlice: [dart.void, [core.List$(core.int), core.int, core.int, core.bool
]] | |
1962 }) | |
1963 }); | |
1964 class _Utf8ConversionSink extends ByteConversionSink { | |
1965 _Utf8ConversionSink(sink, allowMalformed) { | |
1966 this._(sink, new core.StringBuffer(), allowMalformed); | |
1967 } | |
1968 _(chunkedSink, stringBuffer, allowMalformed) { | |
1969 this[_chunkedSink] = chunkedSink; | |
1970 this[_decoder] = new _Utf8Decoder(stringBuffer, allowMalformed); | |
1971 this[_buffer] = stringBuffer; | |
1972 super.ByteConversionSink(); | |
1973 } | |
1974 close() { | |
1975 this[_decoder].close(); | |
1976 if (dart.notNull(this[_buffer].isNotEmpty)) { | |
1977 let accumulated = dart.toString(this[_buffer]); | |
1978 this[_buffer].clear(); | |
1979 this[_chunkedSink].addSlice(accumulated, 0, accumulated[dartx.length], t
rue); | |
1980 } else { | |
1981 this[_chunkedSink].close(); | |
1982 } | |
1983 } | |
1984 add(chunk) { | |
1985 this.addSlice(chunk, 0, chunk[dartx.length], false); | |
1986 } | |
1987 addSlice(chunk, startIndex, endIndex, isLast) { | |
1988 this[_decoder].convert(chunk, startIndex, endIndex); | |
1989 if (dart.notNull(this[_buffer].isNotEmpty)) { | |
1990 let accumulated = dart.toString(this[_buffer]); | |
1991 this[_chunkedSink].addSlice(accumulated, 0, accumulated[dartx.length], i
sLast); | |
1992 this[_buffer].clear(); | |
1993 return; | |
1994 } | |
1995 if (dart.notNull(isLast)) this.close(); | |
1996 } | |
1997 } | |
1998 dart.defineNamedConstructor(_Utf8ConversionSink, '_'); | |
1999 dart.setSignature(_Utf8ConversionSink, { | |
2000 constructors: () => ({ | |
2001 _Utf8ConversionSink: [_Utf8ConversionSink, [StringConversionSink, core.boo
l]], | |
2002 _: [_Utf8ConversionSink, [StringConversionSink, core.StringBuffer, core.bo
ol]] | |
2003 }), | |
2004 methods: () => ({ | |
2005 close: [dart.void, []], | |
2006 add: [dart.void, [core.List$(core.int)]], | |
2007 addSlice: [dart.void, [core.List$(core.int), core.int, core.int, core.bool
]] | |
2008 }) | |
2009 }); | |
2010 const UNICODE_REPLACEMENT_CHARACTER_RUNE = 65533; | |
2011 const UNICODE_BOM_CHARACTER_RUNE = 65279; | |
2012 const _allowMalformed = Symbol('_allowMalformed'); | |
2013 class Utf8Codec extends Encoding { | |
2014 Utf8Codec(opts) { | |
2015 let allowMalformed = opts && 'allowMalformed' in opts ? opts.allowMalforme
d : false; | |
2016 this[_allowMalformed] = allowMalformed; | |
2017 super.Encoding(); | |
2018 } | |
2019 get name() { | |
2020 return "utf-8"; | |
2021 } | |
2022 decode(codeUnits, opts) { | |
2023 let allowMalformed = opts && 'allowMalformed' in opts ? opts.allowMalforme
d : null; | |
2024 if (allowMalformed == null) allowMalformed = this[_allowMalformed]; | |
2025 return new Utf8Decoder({allowMalformed: allowMalformed}).convert(codeUnits
); | |
2026 } | |
2027 get encoder() { | |
2028 return new Utf8Encoder(); | |
2029 } | |
2030 get decoder() { | |
2031 return new Utf8Decoder({allowMalformed: this[_allowMalformed]}); | |
2032 } | |
2033 } | |
2034 dart.setSignature(Utf8Codec, { | |
2035 constructors: () => ({Utf8Codec: [Utf8Codec, [], {allowMalformed: core.bool}
]}), | |
2036 methods: () => ({decode: [core.String, [core.List$(core.int)], {allowMalform
ed: core.bool}]}) | |
2037 }); | |
2038 const UTF8 = dart.const(new Utf8Codec()); | |
2039 const _fillBuffer = Symbol('_fillBuffer'); | |
2040 const _writeSurrogate = Symbol('_writeSurrogate'); | |
2041 class Utf8Encoder extends Converter$(core.String, core.List$(core.int)) { | |
2042 Utf8Encoder() { | |
2043 super.Converter(); | |
2044 } | |
2045 convert(string, start, end) { | |
2046 if (start === void 0) start = 0; | |
2047 if (end === void 0) end = null; | |
2048 let stringLength = string[dartx.length]; | |
2049 core.RangeError.checkValidRange(start, end, stringLength); | |
2050 if (end == null) end = stringLength; | |
2051 let length = dart.notNull(end) - dart.notNull(start); | |
2052 if (length == 0) return typed_data.Uint8List.new(0); | |
2053 let encoder = new _Utf8Encoder.withBufferSize(length * 3); | |
2054 let endPosition = encoder[_fillBuffer](string, start, end); | |
2055 dart.assert(dart.notNull(endPosition) >= dart.notNull(end) - 1); | |
2056 if (endPosition != end) { | |
2057 let lastCodeUnit = string[dartx.codeUnitAt](dart.notNull(end) - 1); | |
2058 dart.assert(_isLeadSurrogate(lastCodeUnit)); | |
2059 let wasCombined = encoder[_writeSurrogate](lastCodeUnit, 0); | |
2060 dart.assert(!dart.notNull(wasCombined)); | |
2061 } | |
2062 return encoder[_buffer][dartx.sublist](0, encoder[_bufferIndex]); | |
2063 } | |
2064 startChunkedConversion(sink) { | |
2065 if (!dart.is(sink, ByteConversionSink)) { | |
2066 sink = ByteConversionSink.from(sink); | |
2067 } | |
2068 return new _Utf8EncoderSink(dart.as(sink, ByteConversionSink)); | |
2069 } | |
2070 bind(stream) { | |
2071 return super.bind(stream); | |
2072 } | |
2073 } | |
2074 dart.setSignature(Utf8Encoder, { | |
2075 constructors: () => ({Utf8Encoder: [Utf8Encoder, []]}), | |
2076 methods: () => ({ | |
2077 convert: [core.List$(core.int), [core.String], [core.int, core.int]], | |
2078 startChunkedConversion: [StringConversionSink, [core.Sink$(core.List$(core
.int))]], | |
2079 bind: [async.Stream$(core.List$(core.int)), [async.Stream$(core.String)]] | |
2080 }) | |
2081 }); | |
2082 class _Utf8Encoder extends core.Object { | |
2083 _Utf8Encoder() { | |
2084 this.withBufferSize(_Utf8Encoder._DEFAULT_BYTE_BUFFER_SIZE); | |
2085 } | |
2086 withBufferSize(bufferSize) { | |
2087 this[_buffer] = _Utf8Encoder._createBuffer(bufferSize); | |
2088 this[_carry] = 0; | |
2089 this[_bufferIndex] = 0; | |
2090 } | |
2091 static _createBuffer(size) { | |
2092 return typed_data.Uint8List.new(size); | |
2093 } | |
2094 [_writeSurrogate](leadingSurrogate, nextCodeUnit) { | |
2095 if (dart.notNull(_isTailSurrogate(nextCodeUnit))) { | |
2096 let rune = _combineSurrogatePair(leadingSurrogate, nextCodeUnit); | |
2097 dart.assert(dart.notNull(rune) > dart.notNull(_THREE_BYTE_LIMIT)); | |
2098 dart.assert(dart.notNull(rune) <= dart.notNull(_FOUR_BYTE_LIMIT)); | |
2099 this[_buffer][dartx.set]((() => { | |
2100 let x = this[_bufferIndex]; | |
2101 this[_bufferIndex] = dart.notNull(x) + 1; | |
2102 return x; | |
2103 })(), 240 | dart.notNull(rune) >> 18); | |
2104 this[_buffer][dartx.set]((() => { | |
2105 let x = this[_bufferIndex]; | |
2106 this[_bufferIndex] = dart.notNull(x) + 1; | |
2107 return x; | |
2108 })(), 128 | dart.notNull(rune) >> 12 & 63); | |
2109 this[_buffer][dartx.set]((() => { | |
2110 let x = this[_bufferIndex]; | |
2111 this[_bufferIndex] = dart.notNull(x) + 1; | |
2112 return x; | |
2113 })(), 128 | dart.notNull(rune) >> 6 & 63); | |
2114 this[_buffer][dartx.set]((() => { | |
2115 let x = this[_bufferIndex]; | |
2116 this[_bufferIndex] = dart.notNull(x) + 1; | |
2117 return x; | |
2118 })(), 128 | dart.notNull(rune) & 63); | |
2119 return true; | |
2120 } else { | |
2121 this[_buffer][dartx.set]((() => { | |
2122 let x = this[_bufferIndex]; | |
2123 this[_bufferIndex] = dart.notNull(x) + 1; | |
2124 return x; | |
2125 })(), 224 | dart.notNull(leadingSurrogate) >> 12); | |
2126 this[_buffer][dartx.set]((() => { | |
2127 let x = this[_bufferIndex]; | |
2128 this[_bufferIndex] = dart.notNull(x) + 1; | |
2129 return x; | |
2130 })(), 128 | dart.notNull(leadingSurrogate) >> 6 & 63); | |
2131 this[_buffer][dartx.set]((() => { | |
2132 let x = this[_bufferIndex]; | |
2133 this[_bufferIndex] = dart.notNull(x) + 1; | |
2134 return x; | |
2135 })(), 128 | dart.notNull(leadingSurrogate) & 63); | |
2136 return false; | |
2137 } | |
2138 } | |
2139 [_fillBuffer](str, start, end) { | |
2140 if (start != end && dart.notNull(_isLeadSurrogate(str[dartx.codeUnitAt](da
rt.notNull(end) - 1)))) { | |
2141 end = dart.notNull(end) - 1; | |
2142 } | |
2143 let stringIndex = null; | |
2144 for (stringIndex = start; dart.notNull(stringIndex) < dart.notNull(end); s
tringIndex = dart.notNull(stringIndex) + 1) { | |
2145 let codeUnit = str[dartx.codeUnitAt](stringIndex); | |
2146 if (dart.notNull(codeUnit) <= dart.notNull(_ONE_BYTE_LIMIT)) { | |
2147 if (dart.notNull(this[_bufferIndex]) >= dart.notNull(this[_buffer][dar
tx.length])) break; | |
2148 this[_buffer][dartx.set]((() => { | |
2149 let x = this[_bufferIndex]; | |
2150 this[_bufferIndex] = dart.notNull(x) + 1; | |
2151 return x; | |
2152 })(), codeUnit); | |
2153 } else if (dart.notNull(_isLeadSurrogate(codeUnit))) { | |
2154 if (dart.notNull(this[_bufferIndex]) + 3 >= dart.notNull(this[_buffer]
[dartx.length])) break; | |
2155 let nextCodeUnit = str[dartx.codeUnitAt](dart.notNull(stringIndex) + 1
); | |
2156 let wasCombined = this[_writeSurrogate](codeUnit, nextCodeUnit); | |
2157 if (dart.notNull(wasCombined)) { | |
2158 stringIndex = dart.notNull(stringIndex) + 1; | |
2159 } | |
2160 } else { | |
2161 let rune = codeUnit; | |
2162 if (dart.notNull(rune) <= dart.notNull(_TWO_BYTE_LIMIT)) { | |
2163 if (dart.notNull(this[_bufferIndex]) + 1 >= dart.notNull(this[_buffe
r][dartx.length])) break; | |
2164 this[_buffer][dartx.set]((() => { | |
2165 let x = this[_bufferIndex]; | |
2166 this[_bufferIndex] = dart.notNull(x) + 1; | |
2167 return x; | |
2168 })(), 192 | dart.notNull(rune) >> 6); | |
2169 this[_buffer][dartx.set]((() => { | |
2170 let x = this[_bufferIndex]; | |
2171 this[_bufferIndex] = dart.notNull(x) + 1; | |
2172 return x; | |
2173 })(), 128 | dart.notNull(rune) & 63); | |
2174 } else { | |
2175 dart.assert(dart.notNull(rune) <= dart.notNull(_THREE_BYTE_LIMIT)); | |
2176 if (dart.notNull(this[_bufferIndex]) + 2 >= dart.notNull(this[_buffe
r][dartx.length])) break; | |
2177 this[_buffer][dartx.set]((() => { | |
2178 let x = this[_bufferIndex]; | |
2179 this[_bufferIndex] = dart.notNull(x) + 1; | |
2180 return x; | |
2181 })(), 224 | dart.notNull(rune) >> 12); | |
2182 this[_buffer][dartx.set]((() => { | |
2183 let x = this[_bufferIndex]; | |
2184 this[_bufferIndex] = dart.notNull(x) + 1; | |
2185 return x; | |
2186 })(), 128 | dart.notNull(rune) >> 6 & 63); | |
2187 this[_buffer][dartx.set]((() => { | |
2188 let x = this[_bufferIndex]; | |
2189 this[_bufferIndex] = dart.notNull(x) + 1; | |
2190 return x; | |
2191 })(), 128 | dart.notNull(rune) & 63); | |
2192 } | |
2193 } | |
2194 } | |
2195 return stringIndex; | |
2196 } | |
2197 } | |
2198 dart.defineNamedConstructor(_Utf8Encoder, 'withBufferSize'); | |
2199 dart.setSignature(_Utf8Encoder, { | |
2200 constructors: () => ({ | |
2201 _Utf8Encoder: [_Utf8Encoder, []], | |
2202 withBufferSize: [_Utf8Encoder, [core.int]] | |
2203 }), | |
2204 methods: () => ({ | |
2205 [_writeSurrogate]: [core.bool, [core.int, core.int]], | |
2206 [_fillBuffer]: [core.int, [core.String, core.int, core.int]] | |
2207 }), | |
2208 statics: () => ({_createBuffer: [core.List$(core.int), [core.int]]}), | |
2209 names: ['_createBuffer'] | |
2210 }); | |
2211 _Utf8Encoder._DEFAULT_BYTE_BUFFER_SIZE = 1024; | |
2212 class _Utf8EncoderSink extends dart.mixin(_Utf8Encoder, StringConversionSinkMi
xin) { | |
2213 _Utf8EncoderSink(sink) { | |
2214 this[_sink] = sink; | |
2215 super._Utf8Encoder(); | |
2216 } | |
2217 close() { | |
2218 if (this[_carry] != 0) { | |
2219 this.addSlice("", 0, 0, true); | |
2220 return; | |
2221 } | |
2222 this[_sink].close(); | |
2223 } | |
2224 addSlice(str, start, end, isLast) { | |
2225 this[_bufferIndex] = 0; | |
2226 if (start == end && !dart.notNull(isLast)) { | |
2227 return; | |
2228 } | |
2229 if (this[_carry] != 0) { | |
2230 let nextCodeUnit = 0; | |
2231 if (start != end) { | |
2232 nextCodeUnit = str[dartx.codeUnitAt](start); | |
2233 } else { | |
2234 dart.assert(isLast); | |
2235 } | |
2236 let wasCombined = this[_writeSurrogate](this[_carry], nextCodeUnit); | |
2237 dart.assert(!dart.notNull(wasCombined) || start != end); | |
2238 if (dart.notNull(wasCombined)) { | |
2239 start = dart.notNull(start) + 1; | |
2240 } | |
2241 this[_carry] = 0; | |
2242 } | |
2243 do { | |
2244 start = this[_fillBuffer](str, start, end); | |
2245 let isLastSlice = dart.notNull(isLast) && start == end; | |
2246 if (start == dart.notNull(end) - 1 && dart.notNull(_isLeadSurrogate(str[
dartx.codeUnitAt](start)))) { | |
2247 if (dart.notNull(isLast) && dart.notNull(this[_bufferIndex]) < dart.no
tNull(this[_buffer][dartx.length]) - 3) { | |
2248 let hasBeenCombined = this[_writeSurrogate](str[dartx.codeUnitAt](st
art), 0); | |
2249 dart.assert(!dart.notNull(hasBeenCombined)); | |
2250 } else { | |
2251 this[_carry] = str[dartx.codeUnitAt](start); | |
2252 } | |
2253 start = dart.notNull(start) + 1; | |
2254 } | |
2255 this[_sink].addSlice(this[_buffer], 0, this[_bufferIndex], isLastSlice); | |
2256 this[_bufferIndex] = 0; | |
2257 } while (dart.notNull(start) < dart.notNull(end)); | |
2258 if (dart.notNull(isLast)) this.close(); | |
2259 } | |
2260 } | |
2261 dart.setSignature(_Utf8EncoderSink, { | |
2262 constructors: () => ({_Utf8EncoderSink: [_Utf8EncoderSink, [ByteConversionSi
nk]]}), | |
2263 methods: () => ({ | |
2264 close: [dart.void, []], | |
2265 addSlice: [dart.void, [core.String, core.int, core.int, core.bool]] | |
2266 }) | |
2267 }); | |
2268 class Utf8Decoder extends Converter$(core.List$(core.int), core.String) { | |
2269 Utf8Decoder(opts) { | |
2270 let allowMalformed = opts && 'allowMalformed' in opts ? opts.allowMalforme
d : false; | |
2271 this[_allowMalformed] = allowMalformed; | |
2272 super.Converter(); | |
2273 } | |
2274 convert(codeUnits, start, end) { | |
2275 if (start === void 0) start = 0; | |
2276 if (end === void 0) end = null; | |
2277 let length = codeUnits[dartx.length]; | |
2278 core.RangeError.checkValidRange(start, end, length); | |
2279 if (end == null) end = length; | |
2280 let buffer = new core.StringBuffer(); | |
2281 let decoder = new _Utf8Decoder(buffer, this[_allowMalformed]); | |
2282 decoder.convert(codeUnits, start, end); | |
2283 decoder.close(); | |
2284 return buffer.toString(); | |
2285 } | |
2286 startChunkedConversion(sink) { | |
2287 let stringSink = null; | |
2288 if (dart.is(sink, StringConversionSink)) { | |
2289 stringSink = sink; | |
2290 } else { | |
2291 stringSink = StringConversionSink.from(sink); | |
2292 } | |
2293 return stringSink.asUtf8Sink(this[_allowMalformed]); | |
2294 } | |
2295 bind(stream) { | |
2296 return super.bind(stream); | |
2297 } | |
2298 fuse(next) { | |
2299 return super.fuse(next); | |
2300 } | |
2301 } | |
2302 dart.setSignature(Utf8Decoder, { | |
2303 constructors: () => ({Utf8Decoder: [Utf8Decoder, [], {allowMalformed: core.b
ool}]}), | |
2304 methods: () => ({ | |
2305 convert: [core.String, [core.List$(core.int)], [core.int, core.int]], | |
2306 startChunkedConversion: [ByteConversionSink, [core.Sink$(core.String)]], | |
2307 bind: [async.Stream$(core.String), [async.Stream$(core.List$(core.int))]], | |
2308 fuse: [Converter$(core.List$(core.int), dart.dynamic), [Converter$(core.St
ring, dart.dynamic)]] | |
2309 }) | |
2310 }); | |
2311 const _ONE_BYTE_LIMIT = 127; | |
2312 const _TWO_BYTE_LIMIT = 2047; | |
2313 const _THREE_BYTE_LIMIT = 65535; | |
2314 const _FOUR_BYTE_LIMIT = 1114111; | |
2315 const _SURROGATE_MASK = 63488; | |
2316 const _SURROGATE_TAG_MASK = 64512; | |
2317 const _SURROGATE_VALUE_MASK = 1023; | |
2318 const _LEAD_SURROGATE_MIN = 55296; | |
2319 const _TAIL_SURROGATE_MIN = 56320; | |
2320 function _isSurrogate(codeUnit) { | |
2321 return (dart.notNull(codeUnit) & dart.notNull(_SURROGATE_MASK)) == _LEAD_SUR
ROGATE_MIN; | |
2322 } | |
2323 dart.fn(_isSurrogate, core.bool, [core.int]); | |
2324 function _isLeadSurrogate(codeUnit) { | |
2325 return (dart.notNull(codeUnit) & dart.notNull(_SURROGATE_TAG_MASK)) == _LEAD
_SURROGATE_MIN; | |
2326 } | |
2327 dart.fn(_isLeadSurrogate, core.bool, [core.int]); | |
2328 function _isTailSurrogate(codeUnit) { | |
2329 return (dart.notNull(codeUnit) & dart.notNull(_SURROGATE_TAG_MASK)) == _TAIL
_SURROGATE_MIN; | |
2330 } | |
2331 dart.fn(_isTailSurrogate, core.bool, [core.int]); | |
2332 function _combineSurrogatePair(lead, tail) { | |
2333 return 65536 + ((dart.notNull(lead) & dart.notNull(_SURROGATE_VALUE_MASK)) <
< 10) | dart.notNull(tail) & dart.notNull(_SURROGATE_VALUE_MASK); | |
2334 } | |
2335 dart.fn(_combineSurrogatePair, core.int, [core.int, core.int]); | |
2336 const _isFirstCharacter = Symbol('_isFirstCharacter'); | |
2337 const _value = Symbol('_value'); | |
2338 const _expectedUnits = Symbol('_expectedUnits'); | |
2339 const _extraUnits = Symbol('_extraUnits'); | |
2340 class _Utf8Decoder extends core.Object { | |
2341 _Utf8Decoder(stringSink, allowMalformed) { | |
2342 this[_stringSink] = stringSink; | |
2343 this[_allowMalformed] = allowMalformed; | |
2344 this[_isFirstCharacter] = true; | |
2345 this[_value] = 0; | |
2346 this[_expectedUnits] = 0; | |
2347 this[_extraUnits] = 0; | |
2348 } | |
2349 get hasPartialInput() { | |
2350 return dart.notNull(this[_expectedUnits]) > 0; | |
2351 } | |
2352 close() { | |
2353 this.flush(); | |
2354 } | |
2355 flush() { | |
2356 if (dart.notNull(this.hasPartialInput)) { | |
2357 if (!dart.notNull(this[_allowMalformed])) { | |
2358 dart.throw(new core.FormatException("Unfinished UTF-8 octet sequence")
); | |
2359 } | |
2360 this[_stringSink].writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE); | |
2361 this[_value] = 0; | |
2362 this[_expectedUnits] = 0; | |
2363 this[_extraUnits] = 0; | |
2364 } | |
2365 } | |
2366 convert(codeUnits, startIndex, endIndex) { | |
2367 let value = this[_value]; | |
2368 let expectedUnits = this[_expectedUnits]; | |
2369 let extraUnits = this[_extraUnits]; | |
2370 this[_value] = 0; | |
2371 this[_expectedUnits] = 0; | |
2372 this[_extraUnits] = 0; | |
2373 function scanOneByteCharacters(units, from) { | |
2374 let to = endIndex; | |
2375 let mask = _ONE_BYTE_LIMIT; | |
2376 for (let i = from; dart.notNull(i) < dart.notNull(to); i = dart.notNull(
i) + 1) { | |
2377 let unit = dart.dindex(units, i); | |
2378 if (!dart.equals(dart.dsend(unit, '&', mask), unit)) return dart.notNu
ll(i) - dart.notNull(from); | |
2379 } | |
2380 return dart.notNull(to) - dart.notNull(from); | |
2381 } | |
2382 dart.fn(scanOneByteCharacters, core.int, [dart.dynamic, core.int]); | |
2383 const addSingleBytes = (function(from, to) { | |
2384 dart.assert(dart.notNull(from) >= dart.notNull(startIndex) && dart.notNu
ll(from) <= dart.notNull(endIndex)); | |
2385 dart.assert(dart.notNull(to) >= dart.notNull(startIndex) && dart.notNull
(to) <= dart.notNull(endIndex)); | |
2386 this[_stringSink].write(core.String.fromCharCodes(codeUnits, from, to)); | |
2387 }).bind(this); | |
2388 dart.fn(addSingleBytes, dart.void, [core.int, core.int]); | |
2389 let i = startIndex; | |
2390 loop: | |
2391 while (true) { | |
2392 multibyte: | |
2393 if (dart.notNull(expectedUnits) > 0) { | |
2394 do { | |
2395 if (i == endIndex) { | |
2396 break loop; | |
2397 } | |
2398 let unit = codeUnits[dartx.get](i); | |
2399 if ((dart.notNull(unit) & 192) != 128) { | |
2400 expectedUnits = 0; | |
2401 if (!dart.notNull(this[_allowMalformed])) { | |
2402 dart.throw(new core.FormatException(`Bad UTF-8 encoding 0x${
unit[dartx.toRadixString](16)}`)); | |
2403 } | |
2404 this[_isFirstCharacter] = false; | |
2405 this[_stringSink].writeCharCode(UNICODE_REPLACEMENT_CHARACTER_
RUNE); | |
2406 break multibyte; | |
2407 } else { | |
2408 value = dart.notNull(value) << 6 | dart.notNull(unit) & 63; | |
2409 expectedUnits = dart.notNull(expectedUnits) - 1; | |
2410 i = dart.notNull(i) + 1; | |
2411 } | |
2412 } while (dart.notNull(expectedUnits) > 0); | |
2413 if (dart.notNull(value) <= dart.notNull(_Utf8Decoder._LIMITS[dartx
.get](dart.notNull(extraUnits) - 1))) { | |
2414 if (!dart.notNull(this[_allowMalformed])) { | |
2415 dart.throw(new core.FormatException(`Overlong encoding of 0x${
value[dartx.toRadixString](16)}`)); | |
2416 } | |
2417 expectedUnits = extraUnits = 0; | |
2418 value = UNICODE_REPLACEMENT_CHARACTER_RUNE; | |
2419 } | |
2420 if (dart.notNull(value) > dart.notNull(_FOUR_BYTE_LIMIT)) { | |
2421 if (!dart.notNull(this[_allowMalformed])) { | |
2422 dart.throw(new core.FormatException("Character outside valid U
nicode range: " + `0x${value[dartx.toRadixString](16)}`)); | |
2423 } | |
2424 value = UNICODE_REPLACEMENT_CHARACTER_RUNE; | |
2425 } | |
2426 if (!dart.notNull(this[_isFirstCharacter]) || value != UNICODE_BOM
_CHARACTER_RUNE) { | |
2427 this[_stringSink].writeCharCode(value); | |
2428 } | |
2429 this[_isFirstCharacter] = false; | |
2430 } | |
2431 while (dart.notNull(i) < dart.notNull(endIndex)) { | |
2432 let oneBytes = scanOneByteCharacters(codeUnits, i); | |
2433 if (dart.notNull(oneBytes) > 0) { | |
2434 this[_isFirstCharacter] = false; | |
2435 addSingleBytes(i, dart.notNull(i) + dart.notNull(oneBytes)); | |
2436 i = dart.notNull(i) + dart.notNull(oneBytes); | |
2437 if (i == endIndex) break; | |
2438 } | |
2439 let unit = codeUnits[dartx.get]((() => { | |
2440 let x = i; | |
2441 i = dart.notNull(x) + 1; | |
2442 return x; | |
2443 })()); | |
2444 if (dart.notNull(unit) < 0) { | |
2445 if (!dart.notNull(this[_allowMalformed])) { | |
2446 dart.throw(new core.FormatException(`Negative UTF-8 code unit: -
0x${(-dart.notNull(unit))[dartx.toRadixString](16)}`)); | |
2447 } | |
2448 this[_stringSink].writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE
); | |
2449 } else { | |
2450 dart.assert(dart.notNull(unit) > dart.notNull(_ONE_BYTE_LIMIT)); | |
2451 if ((dart.notNull(unit) & 224) == 192) { | |
2452 value = dart.notNull(unit) & 31; | |
2453 expectedUnits = extraUnits = 1; | |
2454 continue loop; | |
2455 } | |
2456 if ((dart.notNull(unit) & 240) == 224) { | |
2457 value = dart.notNull(unit) & 15; | |
2458 expectedUnits = extraUnits = 2; | |
2459 continue loop; | |
2460 } | |
2461 if ((dart.notNull(unit) & 248) == 240 && dart.notNull(unit) < 245)
{ | |
2462 value = dart.notNull(unit) & 7; | |
2463 expectedUnits = extraUnits = 3; | |
2464 continue loop; | |
2465 } | |
2466 if (!dart.notNull(this[_allowMalformed])) { | |
2467 dart.throw(new core.FormatException(`Bad UTF-8 encoding 0x${unit
[dartx.toRadixString](16)}`)); | |
2468 } | |
2469 value = UNICODE_REPLACEMENT_CHARACTER_RUNE; | |
2470 expectedUnits = extraUnits = 0; | |
2471 this[_isFirstCharacter] = false; | |
2472 this[_stringSink].writeCharCode(value); | |
2473 } | |
2474 } | |
2475 break loop; | |
2476 } | |
2477 if (dart.notNull(expectedUnits) > 0) { | |
2478 this[_value] = value; | |
2479 this[_expectedUnits] = expectedUnits; | |
2480 this[_extraUnits] = extraUnits; | |
2481 } | |
2482 } | |
2483 } | |
2484 dart.setSignature(_Utf8Decoder, { | |
2485 constructors: () => ({_Utf8Decoder: [_Utf8Decoder, [core.StringSink, core.bo
ol]]}), | |
2486 methods: () => ({ | |
2487 close: [dart.void, []], | |
2488 flush: [dart.void, []], | |
2489 convert: [dart.void, [core.List$(core.int), core.int, core.int]] | |
2490 }) | |
2491 }); | |
2492 _Utf8Decoder._LIMITS = dart.const(dart.list([_ONE_BYTE_LIMIT, _TWO_BYTE_LIMIT,
_THREE_BYTE_LIMIT, _FOUR_BYTE_LIMIT], core.int)); | |
2493 const _processed = Symbol('_processed'); | |
2494 const _computeKeys = Symbol('_computeKeys'); | |
2495 const _original = Symbol('_original'); | |
2496 function _convertJsonToDart(json, reviver) { | |
2497 dart.assert(reviver != null); | |
2498 function walk(e) { | |
2499 if (e == null || typeof e != "object") { | |
2500 return e; | |
2501 } | |
2502 if (Object.getPrototypeOf(e) === Array.prototype) { | |
2503 for (let i = 0; i < e.length; i++) { | |
2504 let item = e[i]; | |
2505 e[i] = dart.dcall(reviver, i, walk(item)); | |
2506 } | |
2507 return e; | |
2508 } | |
2509 let map = new _JsonMap(e); | |
2510 let processed = map[_processed]; | |
2511 let keys = map[_computeKeys](); | |
2512 for (let i = 0; i < dart.notNull(keys[dartx.length]); i++) { | |
2513 let key = keys[dartx.get](i); | |
2514 let revived = dart.dcall(reviver, key, walk(e[key])); | |
2515 processed[key] = revived; | |
2516 } | |
2517 map[_original] = processed; | |
2518 return map; | |
2519 } | |
2520 dart.fn(walk); | |
2521 return dart.dcall(reviver, null, walk(json)); | |
2522 } | |
2523 dart.fn(_convertJsonToDart, dart.dynamic, [dart.dynamic, dart.functionType(dar
t.dynamic, [dart.dynamic, dart.dynamic])]); | |
2524 function _convertJsonToDartLazy(object) { | |
2525 if (object == null) return null; | |
2526 if (typeof object != "object") { | |
2527 return object; | |
2528 } | |
2529 if (Object.getPrototypeOf(object) !== Array.prototype) { | |
2530 return new _JsonMap(object); | |
2531 } | |
2532 for (let i = 0; i < object.length; i++) { | |
2533 let item = object[i]; | |
2534 object[i] = _convertJsonToDartLazy(item); | |
2535 } | |
2536 return object; | |
2537 } | |
2538 dart.fn(_convertJsonToDartLazy); | |
2539 const _data = Symbol('_data'); | |
2540 const _isUpgraded = Symbol('_isUpgraded'); | |
2541 const _upgradedMap = Symbol('_upgradedMap'); | |
2542 const _process = Symbol('_process'); | |
2543 const _upgrade = Symbol('_upgrade'); | |
2544 class _JsonMap extends core.Object { | |
2545 _JsonMap(original) { | |
2546 this[_processed] = _JsonMap._newJavaScriptObject(); | |
2547 this[_original] = original; | |
2548 this[_data] = null; | |
2549 } | |
2550 get(key) { | |
2551 if (dart.notNull(this[_isUpgraded])) { | |
2552 return this[_upgradedMap][dartx.get](key); | |
2553 } else if (!(typeof key == 'string')) { | |
2554 return null; | |
2555 } else { | |
2556 let result = _JsonMap._getProperty(this[_processed], dart.as(key, core.S
tring)); | |
2557 if (dart.notNull(_JsonMap._isUnprocessed(result))) result = this[_proces
s](dart.as(key, core.String)); | |
2558 return result; | |
2559 } | |
2560 } | |
2561 get length() { | |
2562 return dart.notNull(this[_isUpgraded]) ? this[_upgradedMap][dartx.length]
: this[_computeKeys]()[dartx.length]; | |
2563 } | |
2564 get isEmpty() { | |
2565 return this.length == 0; | |
2566 } | |
2567 get isNotEmpty() { | |
2568 return dart.notNull(this.length) > 0; | |
2569 } | |
2570 get keys() { | |
2571 if (dart.notNull(this[_isUpgraded])) return this[_upgradedMap][dartx.keys]
; | |
2572 return new _JsonMapKeyIterable(this); | |
2573 } | |
2574 get values() { | |
2575 if (dart.notNull(this[_isUpgraded])) return this[_upgradedMap][dartx.value
s]; | |
2576 return _internal.MappedIterable.new(this[_computeKeys](), dart.fn(each =>
this.get(each))); | |
2577 } | |
2578 set(key, value) { | |
2579 if (dart.notNull(this[_isUpgraded])) { | |
2580 this[_upgradedMap][dartx.set](key, value); | |
2581 } else if (dart.notNull(this.containsKey(key))) { | |
2582 let processed = this[_processed]; | |
2583 _JsonMap._setProperty(processed, dart.as(key, core.String), value); | |
2584 let original = this[_original]; | |
2585 if (!core.identical(original, processed)) { | |
2586 _JsonMap._setProperty(original, dart.as(key, core.String), null); | |
2587 } | |
2588 } else { | |
2589 this[_upgrade]()[dartx.set](key, value); | |
2590 } | |
2591 return value; | |
2592 } | |
2593 addAll(other) { | |
2594 other[dartx.forEach](dart.fn((key, value) => { | |
2595 this.set(key, value); | |
2596 }, dart.void, [dart.dynamic, dart.dynamic])); | |
2597 } | |
2598 containsValue(value) { | |
2599 if (dart.notNull(this[_isUpgraded])) return this[_upgradedMap][dartx.conta
insValue](value); | |
2600 let keys = this[_computeKeys](); | |
2601 for (let i = 0; i < dart.notNull(keys[dartx.length]); i++) { | |
2602 let key = keys[dartx.get](i); | |
2603 if (dart.equals(this.get(key), value)) return true; | |
2604 } | |
2605 return false; | |
2606 } | |
2607 containsKey(key) { | |
2608 if (dart.notNull(this[_isUpgraded])) return this[_upgradedMap][dartx.conta
insKey](key); | |
2609 if (!(typeof key == 'string')) return false; | |
2610 return _JsonMap._hasProperty(this[_original], dart.as(key, core.String)); | |
2611 } | |
2612 putIfAbsent(key, ifAbsent) { | |
2613 if (dart.notNull(this.containsKey(key))) return this.get(key); | |
2614 let value = ifAbsent(); | |
2615 this.set(key, value); | |
2616 return value; | |
2617 } | |
2618 remove(key) { | |
2619 if (!dart.notNull(this[_isUpgraded]) && !dart.notNull(this.containsKey(key
))) return null; | |
2620 return this[_upgrade]()[dartx.remove](key); | |
2621 } | |
2622 clear() { | |
2623 if (dart.notNull(this[_isUpgraded])) { | |
2624 this[_upgradedMap][dartx.clear](); | |
2625 } else { | |
2626 if (this[_data] != null) { | |
2627 dart.dsend(this[_data], 'clear'); | |
2628 } | |
2629 this[_original] = this[_processed] = null; | |
2630 this[_data] = dart.map(); | |
2631 } | |
2632 } | |
2633 forEach(f) { | |
2634 if (dart.notNull(this[_isUpgraded])) return this[_upgradedMap][dartx.forEa
ch](f); | |
2635 let keys = this[_computeKeys](); | |
2636 for (let i = 0; i < dart.notNull(keys[dartx.length]); i++) { | |
2637 let key = keys[dartx.get](i); | |
2638 let value = _JsonMap._getProperty(this[_processed], key); | |
2639 if (dart.notNull(_JsonMap._isUnprocessed(value))) { | |
2640 value = _convertJsonToDartLazy(_JsonMap._getProperty(this[_original],
key)); | |
2641 _JsonMap._setProperty(this[_processed], key, value); | |
2642 } | |
2643 dart.dcall(f, key, value); | |
2644 if (!core.identical(keys, this[_data])) { | |
2645 dart.throw(new core.ConcurrentModificationError(this)); | |
2646 } | |
2647 } | |
2648 } | |
2649 toString() { | |
2650 return collection.Maps.mapToString(this); | |
2651 } | |
2652 get [_isUpgraded]() { | |
2653 return this[_processed] == null; | |
2654 } | |
2655 get [_upgradedMap]() { | |
2656 dart.assert(this[_isUpgraded]); | |
2657 return dart.as(this[_data], core.Map); | |
2658 } | |
2659 [_computeKeys]() { | |
2660 dart.assert(!dart.notNull(this[_isUpgraded])); | |
2661 let keys = dart.as(this[_data], core.List); | |
2662 if (keys == null) { | |
2663 keys = this[_data] = _JsonMap._getPropertyNames(this[_original]); | |
2664 } | |
2665 return dart.as(keys, core.List$(core.String)); | |
2666 } | |
2667 [_upgrade]() { | |
2668 if (dart.notNull(this[_isUpgraded])) return this[_upgradedMap]; | |
2669 let result = dart.map(); | |
2670 let keys = this[_computeKeys](); | |
2671 for (let i = 0; i < dart.notNull(keys[dartx.length]); i++) { | |
2672 let key = keys[dartx.get](i); | |
2673 result[dartx.set](key, this.get(key)); | |
2674 } | |
2675 if (dart.notNull(keys[dartx.isEmpty])) { | |
2676 keys[dartx.add](null); | |
2677 } else { | |
2678 keys[dartx.clear](); | |
2679 } | |
2680 this[_original] = this[_processed] = null; | |
2681 this[_data] = result; | |
2682 dart.assert(this[_isUpgraded]); | |
2683 return result; | |
2684 } | |
2685 [_process](key) { | |
2686 if (!dart.notNull(_JsonMap._hasProperty(this[_original], key))) return nul
l; | |
2687 let result = _convertJsonToDartLazy(_JsonMap._getProperty(this[_original],
key)); | |
2688 return _JsonMap._setProperty(this[_processed], key, result); | |
2689 } | |
2690 static _hasProperty(object, key) { | |
2691 return Object.prototype.hasOwnProperty.call(object, key); | |
2692 } | |
2693 static _getProperty(object, key) { | |
2694 return object[key]; | |
2695 } | |
2696 static _setProperty(object, key, value) { | |
2697 return object[key] = value; | |
2698 } | |
2699 static _getPropertyNames(object) { | |
2700 return dart.as(Object.keys(object), core.List); | |
2701 } | |
2702 static _isUnprocessed(object) { | |
2703 return typeof object == "undefined"; | |
2704 } | |
2705 static _newJavaScriptObject() { | |
2706 return Object.create(null); | |
2707 } | |
2708 } | |
2709 _JsonMap[dart.implements] = () => [collection.LinkedHashMap]; | |
2710 dart.setSignature(_JsonMap, { | |
2711 constructors: () => ({_JsonMap: [_JsonMap, [dart.dynamic]]}), | |
2712 methods: () => ({ | |
2713 get: [dart.dynamic, [core.Object]], | |
2714 set: [dart.void, [dart.dynamic, dart.dynamic]], | |
2715 addAll: [dart.void, [core.Map]], | |
2716 containsValue: [core.bool, [core.Object]], | |
2717 containsKey: [core.bool, [core.Object]], | |
2718 putIfAbsent: [dart.dynamic, [dart.dynamic, dart.functionType(dart.dynamic,
[])]], | |
2719 remove: [dart.dynamic, [core.Object]], | |
2720 clear: [dart.void, []], | |
2721 forEach: [dart.void, [dart.functionType(dart.void, [dart.dynamic, dart.dyn
amic])]], | |
2722 [_computeKeys]: [core.List$(core.String), []], | |
2723 [_upgrade]: [core.Map, []], | |
2724 [_process]: [dart.dynamic, [core.String]] | |
2725 }), | |
2726 statics: () => ({ | |
2727 _hasProperty: [core.bool, [dart.dynamic, core.String]], | |
2728 _getProperty: [dart.dynamic, [dart.dynamic, core.String]], | |
2729 _setProperty: [dart.dynamic, [dart.dynamic, core.String, dart.dynamic]], | |
2730 _getPropertyNames: [core.List, [dart.dynamic]], | |
2731 _isUnprocessed: [core.bool, [dart.dynamic]], | |
2732 _newJavaScriptObject: [dart.dynamic, []] | |
2733 }), | |
2734 names: ['_hasProperty', '_getProperty', '_setProperty', '_getPropertyNames',
'_isUnprocessed', '_newJavaScriptObject'] | |
2735 }); | |
2736 dart.defineExtensionMembers(_JsonMap, [ | |
2737 'get', | |
2738 'set', | |
2739 'addAll', | |
2740 'containsValue', | |
2741 'containsKey', | |
2742 'putIfAbsent', | |
2743 'remove', | |
2744 'clear', | |
2745 'forEach', | |
2746 'length', | |
2747 'isEmpty', | |
2748 'isNotEmpty', | |
2749 'keys', | |
2750 'values' | |
2751 ]); | |
2752 const _parent = Symbol('_parent'); | |
2753 class _JsonMapKeyIterable extends _internal.ListIterable { | |
2754 _JsonMapKeyIterable(parent) { | |
2755 this[_parent] = parent; | |
2756 super.ListIterable(); | |
2757 } | |
2758 get length() { | |
2759 return this[_parent].length; | |
2760 } | |
2761 elementAt(index) { | |
2762 return dart.as(dart.notNull(this[_parent][_isUpgraded]) ? this[_parent].ke
ys[dartx.elementAt](index) : this[_parent][_computeKeys]()[dartx.get](index), co
re.String); | |
2763 } | |
2764 get iterator() { | |
2765 return dart.notNull(this[_parent][_isUpgraded]) ? this[_parent].keys[dartx
.iterator] : this[_parent][_computeKeys]()[dartx.iterator]; | |
2766 } | |
2767 contains(key) { | |
2768 return this[_parent].containsKey(key); | |
2769 } | |
2770 } | |
2771 dart.setSignature(_JsonMapKeyIterable, { | |
2772 constructors: () => ({_JsonMapKeyIterable: [_JsonMapKeyIterable, [_JsonMap]]
}), | |
2773 methods: () => ({elementAt: [core.String, [core.int]]}) | |
2774 }); | |
2775 dart.defineExtensionMembers(_JsonMapKeyIterable, ['elementAt', 'contains', 'le
ngth', 'iterator']); | |
2776 class _JsonDecoderSink extends _StringSinkConversionSink { | |
2777 _JsonDecoderSink(reviver, sink) { | |
2778 this[_reviver] = reviver; | |
2779 this[_sink] = sink; | |
2780 super._StringSinkConversionSink(new core.StringBuffer()); | |
2781 } | |
2782 close() { | |
2783 super.close(); | |
2784 let buffer = dart.as(this[_stringSink], core.StringBuffer); | |
2785 let accumulated = dart.toString(buffer); | |
2786 buffer.clear(); | |
2787 let decoded = _parseJson(accumulated, this[_reviver]); | |
2788 this[_sink].add(decoded); | |
2789 this[_sink].close(); | |
2790 } | |
2791 } | |
2792 dart.setSignature(_JsonDecoderSink, { | |
2793 constructors: () => ({_JsonDecoderSink: [_JsonDecoderSink, [_Reviver, core.S
ink$(core.Object)]]}) | |
2794 }); | |
2795 // Exports: | |
2796 exports.Codec$ = Codec$; | |
2797 exports.Codec = Codec; | |
2798 exports.Encoding = Encoding; | |
2799 exports.AsciiCodec = AsciiCodec; | |
2800 exports.ASCII = ASCII; | |
2801 exports.Converter$ = Converter$; | |
2802 exports.Converter = Converter; | |
2803 exports.AsciiEncoder = AsciiEncoder; | |
2804 exports.StringConversionSinkMixin = StringConversionSinkMixin; | |
2805 exports.StringConversionSinkBase = StringConversionSinkBase; | |
2806 exports.AsciiDecoder = AsciiDecoder; | |
2807 exports.ChunkedConversionSink$ = ChunkedConversionSink$; | |
2808 exports.ChunkedConversionSink = ChunkedConversionSink; | |
2809 exports.ByteConversionSink = ByteConversionSink; | |
2810 exports.ByteConversionSinkBase = ByteConversionSinkBase; | |
2811 exports.HtmlEscapeMode = HtmlEscapeMode; | |
2812 exports.HtmlEscape = HtmlEscape; | |
2813 exports.HTML_ESCAPE = HTML_ESCAPE; | |
2814 exports.JsonUnsupportedObjectError = JsonUnsupportedObjectError; | |
2815 exports.JsonCyclicError = JsonCyclicError; | |
2816 exports.JsonCodec = JsonCodec; | |
2817 exports.JSON = JSON; | |
2818 exports.JsonEncoder = JsonEncoder; | |
2819 exports.JsonUtf8Encoder = JsonUtf8Encoder; | |
2820 exports.JsonDecoder = JsonDecoder; | |
2821 exports.Latin1Codec = Latin1Codec; | |
2822 exports.LATIN1 = LATIN1; | |
2823 exports.Latin1Encoder = Latin1Encoder; | |
2824 exports.Latin1Decoder = Latin1Decoder; | |
2825 exports.LineSplitter = LineSplitter; | |
2826 exports.StringConversionSink = StringConversionSink; | |
2827 exports.ClosableStringSink = ClosableStringSink; | |
2828 exports.UNICODE_REPLACEMENT_CHARACTER_RUNE = UNICODE_REPLACEMENT_CHARACTER_RUN
E; | |
2829 exports.UNICODE_BOM_CHARACTER_RUNE = UNICODE_BOM_CHARACTER_RUNE; | |
2830 exports.Utf8Codec = Utf8Codec; | |
2831 exports.UTF8 = UTF8; | |
2832 exports.Utf8Encoder = Utf8Encoder; | |
2833 exports.Utf8Decoder = Utf8Decoder; | |
2834 }); | |
OLD | NEW |