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