| OLD | NEW |
| (Empty) |
| 1 var convert; | |
| 2 (function(exports) { | |
| 3 'use strict'; | |
| 4 // Function _convertJsonToDart: (dynamic, (dynamic, dynamic) → dynamic) → dyna
mic | |
| 5 function _convertJsonToDart(json, reviver) { | |
| 6 dart.assert(reviver !== null); | |
| 7 // Function walk: (dynamic) → dynamic | |
| 8 function walk(e) { | |
| 9 if (dart.notNull(e == null) || dart.notNull(typeof e != "object")) { | |
| 10 return e; | |
| 11 } | |
| 12 if (Object.getPrototypeOf(e) === Array.prototype) { | |
| 13 for (let i = 0; i < e.length; i++) { | |
| 14 let item = e[i]; | |
| 15 e[i] = reviver(i, walk(item)); | |
| 16 } | |
| 17 return e; | |
| 18 } | |
| 19 let map = new _JsonMap(e); | |
| 20 let processed = map._processed; | |
| 21 let keys = map._computeKeys(); | |
| 22 for (let i = 0; i < keys.length; i++) { | |
| 23 let key = keys.get(i); | |
| 24 let revived = reviver(key, walk(e[key])); | |
| 25 processed[key] = revived; | |
| 26 } | |
| 27 map._original = processed; | |
| 28 return map; | |
| 29 } | |
| 30 return reviver(null, walk(json)); | |
| 31 } | |
| 32 // Function _convertJsonToDartLazy: (dynamic) → dynamic | |
| 33 function _convertJsonToDartLazy(object) { | |
| 34 if (object === null) | |
| 35 return null; | |
| 36 if (typeof object != "object") { | |
| 37 return object; | |
| 38 } | |
| 39 if (Object.getPrototypeOf(object) !== Array.prototype) { | |
| 40 return new _JsonMap(object); | |
| 41 } | |
| 42 for (let i = 0; i < object.length; i++) { | |
| 43 let item = object[i]; | |
| 44 object[i] = _convertJsonToDartLazy(item); | |
| 45 } | |
| 46 return object; | |
| 47 } | |
| 48 class _JsonMap extends dart.Object { | |
| 49 _JsonMap(_original) { | |
| 50 this._processed = _newJavaScriptObject(); | |
| 51 this._original = _original; | |
| 52 this._data = null; | |
| 53 } | |
| 54 get(key) { | |
| 55 if (this._isUpgraded) { | |
| 56 return this._upgradedMap.get(key); | |
| 57 } else if (!(typeof key == string)) { | |
| 58 return null; | |
| 59 } else { | |
| 60 let result = _getProperty(this._processed, dart.as(key, core.String)); | |
| 61 if (_isUnprocessed(result)) | |
| 62 result = this._process(dart.as(key, core.String)); | |
| 63 return result; | |
| 64 } | |
| 65 } | |
| 66 get length() { | |
| 67 return this._isUpgraded ? this._upgradedMap.length : this._computeKeys().l
ength; | |
| 68 } | |
| 69 get isEmpty() { | |
| 70 return this.length === 0; | |
| 71 } | |
| 72 get isNotEmpty() { | |
| 73 return this.length > 0; | |
| 74 } | |
| 75 get keys() { | |
| 76 if (this._isUpgraded) | |
| 77 return this._upgradedMap.keys; | |
| 78 return new _JsonMapKeyIterable(this); | |
| 79 } | |
| 80 get values() { | |
| 81 if (this._isUpgraded) | |
| 82 return this._upgradedMap.values; | |
| 83 return new _internal.MappedIterable(this._computeKeys(), ((each) => this.g
et(each)).bind(this)); | |
| 84 } | |
| 85 set(key, value) { | |
| 86 if (this._isUpgraded) { | |
| 87 this._upgradedMap.set(key, value); | |
| 88 } else if (this.containsKey(key)) { | |
| 89 let processed = this._processed; | |
| 90 _setProperty(processed, dart.as(key, core.String), value); | |
| 91 let original = this._original; | |
| 92 if (!dart.notNull(core.identical(original, processed))) { | |
| 93 _setProperty(original, dart.as(key, core.String), null); | |
| 94 } | |
| 95 } else { | |
| 96 this._upgrade().set(key, value); | |
| 97 } | |
| 98 } | |
| 99 addAll(other) { | |
| 100 other.forEach(((key, value) => { | |
| 101 this.set(key, value); | |
| 102 }).bind(this)); | |
| 103 } | |
| 104 containsValue(value) { | |
| 105 if (this._isUpgraded) | |
| 106 return this._upgradedMap.containsValue(value); | |
| 107 let keys = this._computeKeys(); | |
| 108 for (let i = 0; i < keys.length; i++) { | |
| 109 let key = keys.get(i); | |
| 110 if (dart.equals(this.get(key), value)) | |
| 111 return true; | |
| 112 } | |
| 113 return false; | |
| 114 } | |
| 115 containsKey(key) { | |
| 116 if (this._isUpgraded) | |
| 117 return this._upgradedMap.containsKey(key); | |
| 118 if (!(typeof key == string)) | |
| 119 return false; | |
| 120 return _hasProperty(this._original, dart.as(key, core.String)); | |
| 121 } | |
| 122 putIfAbsent(key, ifAbsent) { | |
| 123 if (this.containsKey(key)) | |
| 124 return this.get(key); | |
| 125 let value = ifAbsent(); | |
| 126 this.set(key, value); | |
| 127 return value; | |
| 128 } | |
| 129 remove(key) { | |
| 130 if (dart.notNull(!dart.notNull(this._isUpgraded)) && dart.notNull(!dart.no
tNull(this.containsKey(key)))) | |
| 131 return null; | |
| 132 return this._upgrade().remove(key); | |
| 133 } | |
| 134 clear() { | |
| 135 if (this._isUpgraded) { | |
| 136 this._upgradedMap.clear(); | |
| 137 } else { | |
| 138 if (this._data !== null) { | |
| 139 dart.dinvoke(this._data, 'clear'); | |
| 140 } | |
| 141 this._original = this._processed = null; | |
| 142 this._data = dart.map(); | |
| 143 } | |
| 144 } | |
| 145 forEach(f) { | |
| 146 if (this._isUpgraded) | |
| 147 return this._upgradedMap.forEach(f); | |
| 148 let keys = this._computeKeys(); | |
| 149 for (let i = 0; i < keys.length; i++) { | |
| 150 let key = keys.get(i); | |
| 151 let value = _getProperty(this._processed, key); | |
| 152 if (_isUnprocessed(value)) { | |
| 153 value = _convertJsonToDartLazy(_getProperty(this._original, key)); | |
| 154 _setProperty(this._processed, key, value); | |
| 155 } | |
| 156 f(key, value); | |
| 157 if (!dart.notNull(core.identical(keys, this._data))) { | |
| 158 throw new core.ConcurrentModificationError(this); | |
| 159 } | |
| 160 } | |
| 161 } | |
| 162 toString() { | |
| 163 return collection.Maps.mapToString(this); | |
| 164 } | |
| 165 get _isUpgraded() { | |
| 166 return this._processed === null; | |
| 167 } | |
| 168 get _upgradedMap() { | |
| 169 dart.assert(this._isUpgraded); | |
| 170 return dart.as(this._data, core.Map); | |
| 171 } | |
| 172 _computeKeys() { | |
| 173 dart.assert(!dart.notNull(this._isUpgraded)); | |
| 174 let keys = dart.as(this._data, core.List); | |
| 175 if (keys === null) { | |
| 176 keys = this._data = _getPropertyNames(this._original); | |
| 177 } | |
| 178 return dart.as(keys, core.List$(core.String)); | |
| 179 } | |
| 180 _upgrade() { | |
| 181 if (this._isUpgraded) | |
| 182 return this._upgradedMap; | |
| 183 let result = dart.map(); | |
| 184 let keys = this._computeKeys(); | |
| 185 for (let i = 0; i < keys.length; i++) { | |
| 186 let key = keys.get(i); | |
| 187 result.set(key, this.get(key)); | |
| 188 } | |
| 189 if (keys.isEmpty) { | |
| 190 keys.add(null); | |
| 191 } else { | |
| 192 keys.clear(); | |
| 193 } | |
| 194 this._original = this._processed = null; | |
| 195 this._data = result; | |
| 196 dart.assert(this._isUpgraded); | |
| 197 return result; | |
| 198 } | |
| 199 _process(key) { | |
| 200 if (!dart.notNull(_hasProperty(this._original, key))) | |
| 201 return null; | |
| 202 let result = _convertJsonToDartLazy(_getProperty(this._original, key)); | |
| 203 return _setProperty(this._processed, key, result); | |
| 204 } | |
| 205 static _hasProperty(object, key) { | |
| 206 return Object.prototype.hasOwnProperty.call(object, key); | |
| 207 } | |
| 208 static _getProperty(object, key) { | |
| 209 return object[key]; | |
| 210 } | |
| 211 static _setProperty(object, key, value) { | |
| 212 return object[key] = value; | |
| 213 } | |
| 214 static _getPropertyNames(object) { | |
| 215 return dart.as(Object.keys(object), core.List); | |
| 216 } | |
| 217 static _isUnprocessed(object) { | |
| 218 return typeof object == "undefined"; | |
| 219 } | |
| 220 static _newJavaScriptObject() { | |
| 221 return Object.create(null); | |
| 222 } | |
| 223 } | |
| 224 class _JsonMapKeyIterable extends _internal.ListIterable { | |
| 225 _JsonMapKeyIterable(_parent) { | |
| 226 this._parent = _parent; | |
| 227 super.ListIterable(); | |
| 228 } | |
| 229 get length() { | |
| 230 return this._parent.length; | |
| 231 } | |
| 232 elementAt(index) { | |
| 233 return dart.as(this._parent._isUpgraded ? this._parent.keys.elementAt(inde
x) : this._parent._computeKeys().get(index), core.String); | |
| 234 } | |
| 235 get iterator() { | |
| 236 return dart.as(this._parent._isUpgraded ? this._parent.keys.iterator : thi
s._parent._computeKeys().iterator, core.Iterator); | |
| 237 } | |
| 238 contains(key) { | |
| 239 return this._parent.containsKey(key); | |
| 240 } | |
| 241 } | |
| 242 class _JsonDecoderSink extends _StringSinkConversionSink { | |
| 243 _JsonDecoderSink(_reviver, _sink) { | |
| 244 this._reviver = _reviver; | |
| 245 this._sink = _sink; | |
| 246 super._StringSinkConversionSink(new core.StringBuffer()); | |
| 247 } | |
| 248 close() { | |
| 249 super.close(); | |
| 250 let buffer = dart.as(this._stringSink, core.StringBuffer); | |
| 251 let accumulated = buffer.toString(); | |
| 252 buffer.clear(); | |
| 253 let decoded = _parseJson(accumulated, this._reviver); | |
| 254 this._sink.add(decoded); | |
| 255 this._sink.close(); | |
| 256 } | |
| 257 } | |
| 258 let ASCII = new AsciiCodec(); | |
| 259 let _ASCII_MASK = 127; | |
| 260 class AsciiCodec extends Encoding { | |
| 261 AsciiCodec(opt$) { | |
| 262 let allowInvalid = opt$.allowInvalid === void 0 ? false : opt$.allowInvali
d; | |
| 263 this._allowInvalid = allowInvalid; | |
| 264 super.Encoding(); | |
| 265 } | |
| 266 get name() { | |
| 267 return "us-ascii"; | |
| 268 } | |
| 269 decode(bytes, opt$) { | |
| 270 let allowInvalid = opt$.allowInvalid === void 0 ? null : opt$.allowInvalid
; | |
| 271 if (allowInvalid === null) | |
| 272 allowInvalid = this._allowInvalid; | |
| 273 if (allowInvalid) { | |
| 274 return new AsciiDecoder({allowInvalid: true}).convert(bytes); | |
| 275 } else { | |
| 276 return new AsciiDecoder({allowInvalid: false}).convert(bytes); | |
| 277 } | |
| 278 } | |
| 279 get encoder() { | |
| 280 return new AsciiEncoder(); | |
| 281 } | |
| 282 get decoder() { | |
| 283 return this._allowInvalid ? new AsciiDecoder({allowInvalid: true}) : new A
sciiDecoder({allowInvalid: false}); | |
| 284 } | |
| 285 } | |
| 286 class _UnicodeSubsetEncoder extends Converter$(core.String, core.List$(core.in
t)) { | |
| 287 _UnicodeSubsetEncoder(_subsetMask) { | |
| 288 this._subsetMask = _subsetMask; | |
| 289 super.Converter(); | |
| 290 } | |
| 291 convert(string, start, end) { | |
| 292 if (start === void 0) | |
| 293 start = 0; | |
| 294 if (end === void 0) | |
| 295 end = null; | |
| 296 let stringLength = string.length; | |
| 297 core.RangeError.checkValidRange(start, end, stringLength); | |
| 298 if (end === null) | |
| 299 end = stringLength; | |
| 300 let length = end - start; | |
| 301 let result = new typed_data.Uint8List(length); | |
| 302 for (let i = 0; i < length; i++) { | |
| 303 let codeUnit = string.codeUnitAt(start + i); | |
| 304 if ((codeUnit & ~this._subsetMask) !== 0) { | |
| 305 throw new core.ArgumentError("String contains invalid characters."); | |
| 306 } | |
| 307 result.set(i, codeUnit); | |
| 308 } | |
| 309 return dart.as(result, core.List$(core.int)); | |
| 310 } | |
| 311 startChunkedConversion(sink) { | |
| 312 if (!dart.is(sink, ByteConversionSink)) { | |
| 313 sink = new ByteConversionSink.from(sink); | |
| 314 } | |
| 315 return new _UnicodeSubsetEncoderSink(this._subsetMask, dart.as(sink, ByteC
onversionSink)); | |
| 316 } | |
| 317 bind(stream) { | |
| 318 return dart.as(super.bind(stream), async.Stream$(core.List$(core.int))); | |
| 319 } | |
| 320 } | |
| 321 class AsciiEncoder extends _UnicodeSubsetEncoder { | |
| 322 AsciiEncoder() { | |
| 323 super._UnicodeSubsetEncoder(_ASCII_MASK); | |
| 324 } | |
| 325 } | |
| 326 class _UnicodeSubsetEncoderSink extends StringConversionSinkBase { | |
| 327 _UnicodeSubsetEncoderSink(_subsetMask, _sink) { | |
| 328 this._subsetMask = _subsetMask; | |
| 329 this._sink = _sink; | |
| 330 super.StringConversionSinkBase(); | |
| 331 } | |
| 332 close() { | |
| 333 this._sink.close(); | |
| 334 } | |
| 335 addSlice(source, start, end, isLast) { | |
| 336 core.RangeError.checkValidRange(start, end, source.length); | |
| 337 for (let i = start; i < end; i++) { | |
| 338 let codeUnit = source.codeUnitAt(i); | |
| 339 if ((codeUnit & ~this._subsetMask) !== 0) { | |
| 340 throw new core.ArgumentError(`Source contains invalid character with c
ode point: ${codeUnit}.`); | |
| 341 } | |
| 342 } | |
| 343 this._sink.add(source.codeUnits.sublist(start, end)); | |
| 344 if (isLast) { | |
| 345 this.close(); | |
| 346 } | |
| 347 } | |
| 348 } | |
| 349 class _UnicodeSubsetDecoder extends Converter$(core.List$(core.int), core.Stri
ng) { | |
| 350 _UnicodeSubsetDecoder(_allowInvalid, _subsetMask) { | |
| 351 this._allowInvalid = _allowInvalid; | |
| 352 this._subsetMask = _subsetMask; | |
| 353 super.Converter(); | |
| 354 } | |
| 355 convert(bytes, start, end) { | |
| 356 if (start === void 0) | |
| 357 start = 0; | |
| 358 if (end === void 0) | |
| 359 end = null; | |
| 360 let byteCount = bytes.length; | |
| 361 core.RangeError.checkValidRange(start, end, byteCount); | |
| 362 if (end === null) | |
| 363 end = byteCount; | |
| 364 let length = end - start; | |
| 365 for (let i = start; i < end; i++) { | |
| 366 let byte = bytes.get(i); | |
| 367 if ((byte & ~this._subsetMask) !== 0) { | |
| 368 if (!dart.notNull(this._allowInvalid)) { | |
| 369 throw new core.FormatException(`Invalid value in input: ${byte}`); | |
| 370 } | |
| 371 return this._convertInvalid(bytes, start, end); | |
| 372 } | |
| 373 } | |
| 374 return new core.String.fromCharCodes(bytes, start, end); | |
| 375 } | |
| 376 _convertInvalid(bytes, start, end) { | |
| 377 let buffer = new core.StringBuffer(); | |
| 378 for (let i = start; i < end; i++) { | |
| 379 let value = bytes.get(i); | |
| 380 if ((value & ~this._subsetMask) !== 0) | |
| 381 value = 65533; | |
| 382 buffer.writeCharCode(value); | |
| 383 } | |
| 384 return buffer.toString(); | |
| 385 } | |
| 386 bind(stream) { | |
| 387 return dart.as(super.bind(stream), async.Stream$(core.String)); | |
| 388 } | |
| 389 } | |
| 390 class AsciiDecoder extends _UnicodeSubsetDecoder { | |
| 391 AsciiDecoder(opt$) { | |
| 392 let allowInvalid = opt$.allowInvalid === void 0 ? false : opt$.allowInvali
d; | |
| 393 super._UnicodeSubsetDecoder(allowInvalid, _ASCII_MASK); | |
| 394 } | |
| 395 startChunkedConversion(sink) { | |
| 396 let stringSink = null; | |
| 397 if (dart.is(sink, StringConversionSink)) { | |
| 398 stringSink = sink; | |
| 399 } else { | |
| 400 stringSink = new StringConversionSink.from(sink); | |
| 401 } | |
| 402 if (this._allowInvalid) { | |
| 403 return new _ErrorHandlingAsciiDecoderSink(stringSink.asUtf8Sink(false)); | |
| 404 } else { | |
| 405 return new _SimpleAsciiDecoderSink(stringSink); | |
| 406 } | |
| 407 } | |
| 408 } | |
| 409 class _ErrorHandlingAsciiDecoderSink extends ByteConversionSinkBase { | |
| 410 _ErrorHandlingAsciiDecoderSink(_utf8Sink) { | |
| 411 this._utf8Sink = _utf8Sink; | |
| 412 super.ByteConversionSinkBase(); | |
| 413 } | |
| 414 close() { | |
| 415 this._utf8Sink.close(); | |
| 416 } | |
| 417 add(source) { | |
| 418 this.addSlice(source, 0, source.length, false); | |
| 419 } | |
| 420 addSlice(source, start, end, isLast) { | |
| 421 core.RangeError.checkValidRange(start, end, source.length); | |
| 422 for (let i = start; i < end; i++) { | |
| 423 if ((source.get(i) & ~_ASCII_MASK) !== 0) { | |
| 424 if (i > start) | |
| 425 this._utf8Sink.addSlice(source, start, i, false); | |
| 426 this._utf8Sink.add(/* Unimplemented const */new List.from([239, 191, 1
89])); | |
| 427 start = i + 1; | |
| 428 } | |
| 429 } | |
| 430 if (start < end) { | |
| 431 this._utf8Sink.addSlice(source, start, end, isLast); | |
| 432 } else if (isLast) { | |
| 433 this.close(); | |
| 434 } | |
| 435 } | |
| 436 } | |
| 437 class _SimpleAsciiDecoderSink extends ByteConversionSinkBase { | |
| 438 _SimpleAsciiDecoderSink(_sink) { | |
| 439 this._sink = _sink; | |
| 440 super.ByteConversionSinkBase(); | |
| 441 } | |
| 442 close() { | |
| 443 this._sink.close(); | |
| 444 } | |
| 445 add(source) { | |
| 446 for (let i = 0; i < source.length; i++) { | |
| 447 if ((source.get(i) & ~_ASCII_MASK) !== 0) { | |
| 448 throw new core.FormatException("Source contains non-ASCII bytes."); | |
| 449 } | |
| 450 } | |
| 451 this._sink.add(new core.String.fromCharCodes(source)); | |
| 452 } | |
| 453 addSlice(source, start, end, isLast) { | |
| 454 let length = source.length; | |
| 455 core.RangeError.checkValidRange(start, end, length); | |
| 456 if (start < end) { | |
| 457 if (dart.notNull(start !== 0) || dart.notNull(end !== length)) { | |
| 458 source = source.sublist(start, end); | |
| 459 } | |
| 460 this.add(source); | |
| 461 } | |
| 462 if (isLast) | |
| 463 this.close(); | |
| 464 } | |
| 465 } | |
| 466 class ByteConversionSink extends ChunkedConversionSink$(core.List$(core.int))
{ | |
| 467 ByteConversionSink() { | |
| 468 super.ChunkedConversionSink(); | |
| 469 } | |
| 470 ByteConversionSink$withCallback(callback) { | |
| 471 return new _ByteCallbackSink(callback); | |
| 472 } | |
| 473 ByteConversionSink$from(sink) { | |
| 474 return new _ByteAdapterSink(sink); | |
| 475 } | |
| 476 } | |
| 477 dart.defineNamedConstructor(ByteConversionSink, 'withCallback'); | |
| 478 dart.defineNamedConstructor(ByteConversionSink, 'from'); | |
| 479 class ByteConversionSinkBase extends ByteConversionSink { | |
| 480 addSlice(chunk, start, end, isLast) { | |
| 481 this.add(chunk.sublist(start, end)); | |
| 482 if (isLast) | |
| 483 this.close(); | |
| 484 } | |
| 485 } | |
| 486 class _ByteAdapterSink extends ByteConversionSinkBase { | |
| 487 _ByteAdapterSink(_sink) { | |
| 488 this._sink = _sink; | |
| 489 super.ByteConversionSinkBase(); | |
| 490 } | |
| 491 add(chunk) { | |
| 492 return this._sink.add(chunk); | |
| 493 } | |
| 494 close() { | |
| 495 return this._sink.close(); | |
| 496 } | |
| 497 } | |
| 498 class _ByteCallbackSink extends ByteConversionSinkBase { | |
| 499 _ByteCallbackSink(callback) { | |
| 500 this._buffer = new typed_data.Uint8List(dart.as(_INITIAL_BUFFER_SIZE, core
.int)); | |
| 501 this._callback = callback; | |
| 502 this._bufferIndex = 0; | |
| 503 super.ByteConversionSinkBase(); | |
| 504 } | |
| 505 add(chunk) { | |
| 506 let freeCount = this._buffer.length - this._bufferIndex; | |
| 507 if (chunk.length > freeCount) { | |
| 508 let oldLength = this._buffer.length; | |
| 509 let newLength = _roundToPowerOf2(chunk.length + oldLength) * 2; | |
| 510 let grown = new typed_data.Uint8List(newLength); | |
| 511 grown.setRange(0, this._buffer.length, this._buffer); | |
| 512 this._buffer = grown; | |
| 513 } | |
| 514 this._buffer.setRange(this._bufferIndex, this._bufferIndex + chunk.length,
chunk); | |
| 515 this._bufferIndex = chunk.length; | |
| 516 } | |
| 517 static _roundToPowerOf2(v) { | |
| 518 dart.assert(v > 0); | |
| 519 v--; | |
| 520 v = v >> 1; | |
| 521 v = v >> 2; | |
| 522 v = v >> 4; | |
| 523 v = v >> 8; | |
| 524 v = v >> 16; | |
| 525 v++; | |
| 526 return v; | |
| 527 } | |
| 528 close() { | |
| 529 this._callback(this._buffer.sublist(0, this._bufferIndex)); | |
| 530 } | |
| 531 } | |
| 532 _ByteCallbackSink._INITIAL_BUFFER_SIZE = 1024; | |
| 533 let ChunkedConversionSink$ = dart.generic(function(T) { | |
| 534 class ChunkedConversionSink extends dart.Object { | |
| 535 ChunkedConversionSink() { | |
| 536 } | |
| 537 ChunkedConversionSink$withCallback(callback) { | |
| 538 return new _SimpleCallbackSink(callback); | |
| 539 } | |
| 540 } | |
| 541 dart.defineNamedConstructor(ChunkedConversionSink, 'withCallback'); | |
| 542 return ChunkedConversionSink; | |
| 543 }); | |
| 544 let ChunkedConversionSink = ChunkedConversionSink$(dynamic); | |
| 545 let _SimpleCallbackSink$ = dart.generic(function(T) { | |
| 546 class _SimpleCallbackSink extends ChunkedConversionSink$(T) { | |
| 547 _SimpleCallbackSink(_callback) { | |
| 548 this._accumulated = new List.from([]); | |
| 549 this._callback = _callback; | |
| 550 super.ChunkedConversionSink(); | |
| 551 } | |
| 552 add(chunk) { | |
| 553 this._accumulated.add(chunk); | |
| 554 } | |
| 555 close() { | |
| 556 this._callback(this._accumulated); | |
| 557 } | |
| 558 } | |
| 559 return _SimpleCallbackSink; | |
| 560 }); | |
| 561 let _SimpleCallbackSink = _SimpleCallbackSink$(dynamic); | |
| 562 let _EventSinkAdapter$ = dart.generic(function(T) { | |
| 563 class _EventSinkAdapter extends dart.Object { | |
| 564 _EventSinkAdapter(_sink) { | |
| 565 this._sink = _sink; | |
| 566 } | |
| 567 add(data) { | |
| 568 return this._sink.add(data); | |
| 569 } | |
| 570 close() { | |
| 571 return this._sink.close(); | |
| 572 } | |
| 573 } | |
| 574 return _EventSinkAdapter; | |
| 575 }); | |
| 576 let _EventSinkAdapter = _EventSinkAdapter$(dynamic); | |
| 577 let _ConverterStreamEventSink$ = dart.generic(function(S, T) { | |
| 578 class _ConverterStreamEventSink extends dart.Object { | |
| 579 _ConverterStreamEventSink(converter, sink) { | |
| 580 this._eventSink = sink; | |
| 581 this._chunkedSink = converter.startChunkedConversion(sink); | |
| 582 } | |
| 583 add(o) { | |
| 584 return this._chunkedSink.add(o); | |
| 585 } | |
| 586 addError(error, stackTrace) { | |
| 587 if (stackTrace === void 0) | |
| 588 stackTrace = null; | |
| 589 this._eventSink.addError(error, stackTrace); | |
| 590 } | |
| 591 close() { | |
| 592 return this._chunkedSink.close(); | |
| 593 } | |
| 594 } | |
| 595 return _ConverterStreamEventSink; | |
| 596 }); | |
| 597 let _ConverterStreamEventSink = _ConverterStreamEventSink$(dynamic, dynamic); | |
| 598 let Codec$ = dart.generic(function(S, T) { | |
| 599 class Codec extends dart.Object { | |
| 600 Codec() { | |
| 601 } | |
| 602 encode(input) { | |
| 603 return this.encoder.convert(input); | |
| 604 } | |
| 605 decode(encoded) { | |
| 606 return this.decoder.convert(encoded); | |
| 607 } | |
| 608 fuse(other) { | |
| 609 return new _FusedCodec(this, other); | |
| 610 } | |
| 611 get inverted() { | |
| 612 return new _InvertedCodec(this); | |
| 613 } | |
| 614 } | |
| 615 return Codec; | |
| 616 }); | |
| 617 let Codec = Codec$(dynamic, dynamic); | |
| 618 let _FusedCodec$ = dart.generic(function(S, M, T) { | |
| 619 class _FusedCodec extends Codec$(S, T) { | |
| 620 get encoder() { | |
| 621 return dart.as(this._first.encoder.fuse(this._second.encoder), Converter
$(S, T)); | |
| 622 } | |
| 623 get decoder() { | |
| 624 return dart.as(this._second.decoder.fuse(this._first.decoder), Converter
$(T, S)); | |
| 625 } | |
| 626 _FusedCodec(_first, _second) { | |
| 627 this._first = _first; | |
| 628 this._second = _second; | |
| 629 super.Codec(); | |
| 630 } | |
| 631 } | |
| 632 return _FusedCodec; | |
| 633 }); | |
| 634 let _FusedCodec = _FusedCodec$(dynamic, dynamic, dynamic); | |
| 635 let _InvertedCodec$ = dart.generic(function(T, S) { | |
| 636 class _InvertedCodec extends Codec$(T, S) { | |
| 637 _InvertedCodec(codec) { | |
| 638 this._codec = codec; | |
| 639 super.Codec(); | |
| 640 } | |
| 641 get encoder() { | |
| 642 return this._codec.decoder; | |
| 643 } | |
| 644 get decoder() { | |
| 645 return this._codec.encoder; | |
| 646 } | |
| 647 get inverted() { | |
| 648 return this._codec; | |
| 649 } | |
| 650 } | |
| 651 return _InvertedCodec; | |
| 652 }); | |
| 653 let _InvertedCodec = _InvertedCodec$(dynamic, dynamic); | |
| 654 let Converter$ = dart.generic(function(S, T) { | |
| 655 class Converter extends dart.Object { | |
| 656 Converter() { | |
| 657 } | |
| 658 fuse(other) { | |
| 659 return new _FusedConverter(this, other); | |
| 660 } | |
| 661 startChunkedConversion(sink) { | |
| 662 throw new core.UnsupportedError(`This converter does not support chunked
conversions: ${this}`); | |
| 663 } | |
| 664 bind(source) { | |
| 665 return new async.Stream.eventTransformed(source, ((sink) => new _Convert
erStreamEventSink(this, sink)).bind(this)); | |
| 666 } | |
| 667 } | |
| 668 return Converter; | |
| 669 }); | |
| 670 let Converter = Converter$(dynamic, dynamic); | |
| 671 let _FusedConverter$ = dart.generic(function(S, M, T) { | |
| 672 class _FusedConverter extends Converter$(S, T) { | |
| 673 _FusedConverter(_first, _second) { | |
| 674 this._first = _first; | |
| 675 this._second = _second; | |
| 676 super.Converter(); | |
| 677 } | |
| 678 convert(input) { | |
| 679 return dart.as(this._second.convert(this._first.convert(input)), T); | |
| 680 } | |
| 681 startChunkedConversion(sink) { | |
| 682 return this._first.startChunkedConversion(this._second.startChunkedConve
rsion(sink)); | |
| 683 } | |
| 684 } | |
| 685 return _FusedConverter; | |
| 686 }); | |
| 687 let _FusedConverter = _FusedConverter$(dynamic, dynamic, dynamic); | |
| 688 class Encoding extends Codec$(core.String, core.List$(core.int)) { | |
| 689 Encoding() { | |
| 690 super.Codec(); | |
| 691 } | |
| 692 decodeStream(byteStream) { | |
| 693 return dart.as(byteStream.transform(dart.as(this.decoder, async.StreamTran
sformer$(core.List$(core.int), dynamic))).fold(new core.StringBuffer(), (buffer,
string) => dart.dinvoke(buffer, 'write', string), buffer).then((buffer) => dart
.dinvoke(buffer, 'toString')), async.Future$(core.String)); | |
| 694 } | |
| 695 static getByName(name) { | |
| 696 if (name === null) | |
| 697 return null; | |
| 698 name = name.toLowerCase(); | |
| 699 return _nameToEncoding.get(name); | |
| 700 } | |
| 701 } | |
| 702 dart.defineLazyProperties(Encoding, { | |
| 703 get _nameToEncoding() { | |
| 704 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}); | |
| 705 }, | |
| 706 set _nameToEncoding() {} | |
| 707 }); | |
| 708 let HTML_ESCAPE = new HtmlEscape(); | |
| 709 class HtmlEscapeMode extends dart.Object { | |
| 710 HtmlEscapeMode$_(_name, escapeLtGt, escapeQuot, escapeApos, escapeSlash) { | |
| 711 this._name = _name; | |
| 712 this.escapeLtGt = escapeLtGt; | |
| 713 this.escapeQuot = escapeQuot; | |
| 714 this.escapeApos = escapeApos; | |
| 715 this.escapeSlash = escapeSlash; | |
| 716 } | |
| 717 toString() { | |
| 718 return this._name; | |
| 719 } | |
| 720 } | |
| 721 dart.defineNamedConstructor(HtmlEscapeMode, '_'); | |
| 722 HtmlEscapeMode.UNKNOWN = new HtmlEscapeMode._('unknown', true, true, true, tru
e); | |
| 723 HtmlEscapeMode.ATTRIBUTE = new HtmlEscapeMode._('attribute', false, true, fals
e, false); | |
| 724 HtmlEscapeMode.ELEMENT = new HtmlEscapeMode._('element', true, false, false, t
rue); | |
| 725 class HtmlEscape extends Converter$(core.String, core.String) { | |
| 726 HtmlEscape(mode) { | |
| 727 if (mode === void 0) | |
| 728 mode = HtmlEscapeMode.UNKNOWN; | |
| 729 this.mode = mode; | |
| 730 super.Converter(); | |
| 731 } | |
| 732 convert(text) { | |
| 733 let val = this._convert(text, 0, text.length); | |
| 734 return val === null ? text : val; | |
| 735 } | |
| 736 _convert(text, start, end) { | |
| 737 let result = null; | |
| 738 for (let i = start; i < end; i++) { | |
| 739 let ch = text.get(i); | |
| 740 let replace = null; | |
| 741 switch (ch) { | |
| 742 case '&': | |
| 743 replace = '&'; | |
| 744 break; | |
| 745 case ' ': | |
| 746 replace = ' '; | |
| 747 break; | |
| 748 case '"': | |
| 749 if (this.mode.escapeQuot) | |
| 750 replace = '"'; | |
| 751 break; | |
| 752 case "'": | |
| 753 if (this.mode.escapeApos) | |
| 754 replace = '''; | |
| 755 break; | |
| 756 case '<': | |
| 757 if (this.mode.escapeLtGt) | |
| 758 replace = '<'; | |
| 759 break; | |
| 760 case '>': | |
| 761 if (this.mode.escapeLtGt) | |
| 762 replace = '>'; | |
| 763 break; | |
| 764 case '/': | |
| 765 if (this.mode.escapeSlash) | |
| 766 replace = '/'; | |
| 767 break; | |
| 768 } | |
| 769 if (replace !== null) { | |
| 770 if (result === null) | |
| 771 result = new core.StringBuffer(text.substring(start, i)); | |
| 772 result.write(replace); | |
| 773 } else if (result !== null) { | |
| 774 result.write(ch); | |
| 775 } | |
| 776 } | |
| 777 return dart.as(result !== null ? result.toString() : null, core.String); | |
| 778 } | |
| 779 startChunkedConversion(sink) { | |
| 780 if (!dart.is(sink, StringConversionSink)) { | |
| 781 sink = new StringConversionSink.from(sink); | |
| 782 } | |
| 783 return new _HtmlEscapeSink(this, dart.as(sink, StringConversionSink)); | |
| 784 } | |
| 785 } | |
| 786 class _HtmlEscapeSink extends StringConversionSinkBase { | |
| 787 _HtmlEscapeSink(_escape, _sink) { | |
| 788 this._escape = _escape; | |
| 789 this._sink = _sink; | |
| 790 super.StringConversionSinkBase(); | |
| 791 } | |
| 792 addSlice(chunk, start, end, isLast) { | |
| 793 let val = this._escape._convert(chunk, start, end); | |
| 794 if (val === null) { | |
| 795 this._sink.addSlice(chunk, start, end, isLast); | |
| 796 } else { | |
| 797 this._sink.add(val); | |
| 798 if (isLast) | |
| 799 this._sink.close(); | |
| 800 } | |
| 801 } | |
| 802 close() { | |
| 803 return this._sink.close(); | |
| 804 } | |
| 805 } | |
| 806 class JsonUnsupportedObjectError extends core.Error { | |
| 807 JsonUnsupportedObjectError(unsupportedObject, opt$) { | |
| 808 let cause = opt$.cause === void 0 ? null : opt$.cause; | |
| 809 this.unsupportedObject = unsupportedObject; | |
| 810 this.cause = cause; | |
| 811 super.Error(); | |
| 812 } | |
| 813 toString() { | |
| 814 if (this.cause !== null) { | |
| 815 return "Converting object to an encodable object failed."; | |
| 816 } else { | |
| 817 return "Converting object did not return an encodable object."; | |
| 818 } | |
| 819 } | |
| 820 } | |
| 821 class JsonCyclicError extends JsonUnsupportedObjectError { | |
| 822 JsonCyclicError(object) { | |
| 823 super.JsonUnsupportedObjectError(object); | |
| 824 } | |
| 825 toString() { | |
| 826 return "Cyclic error in JSON stringify"; | |
| 827 } | |
| 828 } | |
| 829 let JSON = new JsonCodec(); | |
| 830 class JsonCodec extends Codec$(core.Object, core.String) { | |
| 831 JsonCodec(opt$) { | |
| 832 let reviver = opt$.reviver === void 0 ? null : opt$.reviver; | |
| 833 let toEncodable = opt$.toEncodable === void 0 ? null : opt$.toEncodable; | |
| 834 this._reviver = reviver; | |
| 835 this._toEncodable = toEncodable; | |
| 836 super.Codec(); | |
| 837 } | |
| 838 JsonCodec$withReviver(reviver) { | |
| 839 this.JsonCodec({reviver: reviver}); | |
| 840 } | |
| 841 decode(source, opt$) { | |
| 842 let reviver = opt$.reviver === void 0 ? null : opt$.reviver; | |
| 843 if (reviver === null) | |
| 844 reviver = this._reviver; | |
| 845 if (reviver === null) | |
| 846 return this.decoder.convert(source); | |
| 847 return new JsonDecoder(reviver).convert(source); | |
| 848 } | |
| 849 encode(value, opt$) { | |
| 850 let toEncodable = opt$.toEncodable === void 0 ? null : opt$.toEncodable; | |
| 851 if (toEncodable === null) | |
| 852 toEncodable = this._toEncodable; | |
| 853 if (toEncodable === null) | |
| 854 return this.encoder.convert(value); | |
| 855 return new JsonEncoder(dart.as(toEncodable, dart.throw_("Unimplemented typ
e (Object) → Object"))).convert(value); | |
| 856 } | |
| 857 get encoder() { | |
| 858 if (this._toEncodable === null) | |
| 859 return new JsonEncoder(); | |
| 860 return new JsonEncoder(dart.as(this._toEncodable, dart.throw_("Unimplement
ed type (Object) → Object"))); | |
| 861 } | |
| 862 get decoder() { | |
| 863 if (this._reviver === null) | |
| 864 return new JsonDecoder(); | |
| 865 return new JsonDecoder(this._reviver); | |
| 866 } | |
| 867 } | |
| 868 dart.defineNamedConstructor(JsonCodec, 'withReviver'); | |
| 869 class JsonEncoder extends Converter$(core.Object, core.String) { | |
| 870 JsonEncoder(toEncodable) { | |
| 871 if (toEncodable === void 0) | |
| 872 toEncodable = null; | |
| 873 this.indent = null; | |
| 874 this._toEncodable = toEncodable; | |
| 875 super.Converter(); | |
| 876 } | |
| 877 JsonEncoder$withIndent(indent, toEncodable) { | |
| 878 if (toEncodable === void 0) | |
| 879 toEncodable = null; | |
| 880 this.indent = indent; | |
| 881 this._toEncodable = toEncodable; | |
| 882 super.Converter(); | |
| 883 } | |
| 884 convert(object) { | |
| 885 return _JsonStringStringifier.stringify(object, dart.as(this._toEncodable,
dart.throw_("Unimplemented type (dynamic) → dynamic")), this.indent); | |
| 886 } | |
| 887 startChunkedConversion(sink) { | |
| 888 if (!dart.is(sink, StringConversionSink)) { | |
| 889 sink = new StringConversionSink.from(sink); | |
| 890 } else if (dart.is(sink, _Utf8EncoderSink)) { | |
| 891 return new _JsonUtf8EncoderSink(sink._sink, this._toEncodable, JsonUtf8E
ncoder._utf8Encode(this.indent), JsonUtf8Encoder.DEFAULT_BUFFER_SIZE); | |
| 892 } | |
| 893 return new _JsonEncoderSink(dart.as(sink, StringConversionSink), this._toE
ncodable, this.indent); | |
| 894 } | |
| 895 bind(stream) { | |
| 896 return dart.as(super.bind(stream), async.Stream$(core.String)); | |
| 897 } | |
| 898 fuse(other) { | |
| 899 if (dart.is(other, Utf8Encoder)) { | |
| 900 return new JsonUtf8Encoder(this.indent, dart.as(this._toEncodable, dart.
throw_("Unimplemented type (Object) → dynamic"))); | |
| 901 } | |
| 902 return super.fuse(other); | |
| 903 } | |
| 904 } | |
| 905 dart.defineNamedConstructor(JsonEncoder, 'withIndent'); | |
| 906 class JsonUtf8Encoder extends Converter$(core.Object, core.List$(core.int)) { | |
| 907 JsonUtf8Encoder(indent, toEncodable, bufferSize) { | |
| 908 if (indent === void 0) | |
| 909 indent = null; | |
| 910 if (toEncodable === void 0) | |
| 911 toEncodable = null; | |
| 912 if (bufferSize === void 0) | |
| 913 bufferSize = DEFAULT_BUFFER_SIZE; | |
| 914 this._indent = _utf8Encode(indent); | |
| 915 this._toEncodable = toEncodable; | |
| 916 this._bufferSize = bufferSize; | |
| 917 super.Converter(); | |
| 918 } | |
| 919 static _utf8Encode(string) { | |
| 920 if (string === null) | |
| 921 return null; | |
| 922 if (string.isEmpty) | |
| 923 return new typed_data.Uint8List(0); | |
| 924 checkAscii: { | |
| 925 for (let i = 0; i < string.length; i++) { | |
| 926 if (string.codeUnitAt(i) >= 128) | |
| 927 break checkAscii; | |
| 928 } | |
| 929 return string.codeUnits; | |
| 930 } | |
| 931 return UTF8.encode(string); | |
| 932 } | |
| 933 convert(object) { | |
| 934 let bytes = dart.as(new List.from([]), core.List$(core.List$(core.int))); | |
| 935 // Function addChunk: (Uint8List, int, int) → void | |
| 936 function addChunk(chunk, start, end) { | |
| 937 if (dart.notNull(start > 0) || dart.notNull(end < chunk.length)) { | |
| 938 let length = end - start; | |
| 939 chunk = new typed_data.Uint8List.view(chunk.buffer, chunk.offsetInByte
s + start, length); | |
| 940 } | |
| 941 bytes.add(chunk); | |
| 942 } | |
| 943 _JsonUtf8Stringifier.stringify(object, this._indent, dart.as(this._toEncod
able, dart.throw_("Unimplemented type (Object) → dynamic")), this._bufferSize, a
ddChunk); | |
| 944 if (bytes.length === 1) | |
| 945 return bytes.get(0); | |
| 946 let length = 0; | |
| 947 for (let i = 0; i < bytes.length; i++) { | |
| 948 length = bytes.get(i).length; | |
| 949 } | |
| 950 let result = new typed_data.Uint8List(length); | |
| 951 for (let i = 0, offset = 0; i < bytes.length; i++) { | |
| 952 let byteList = bytes.get(i); | |
| 953 let end = offset + byteList.length; | |
| 954 result.setRange(offset, end, byteList); | |
| 955 offset = end; | |
| 956 } | |
| 957 return result; | |
| 958 } | |
| 959 startChunkedConversion(sink) { | |
| 960 let byteSink = null; | |
| 961 if (dart.is(sink, ByteConversionSink)) { | |
| 962 byteSink = sink; | |
| 963 } else { | |
| 964 byteSink = new ByteConversionSink.from(sink); | |
| 965 } | |
| 966 return new _JsonUtf8EncoderSink(byteSink, this._toEncodable, this._indent,
this._bufferSize); | |
| 967 } | |
| 968 bind(stream) { | |
| 969 return dart.as(super.bind(stream), async.Stream$(core.List$(core.int))); | |
| 970 } | |
| 971 fuse(other) { | |
| 972 return super.fuse(other); | |
| 973 } | |
| 974 } | |
| 975 JsonUtf8Encoder.DEFAULT_BUFFER_SIZE = 256; | |
| 976 class _JsonEncoderSink extends ChunkedConversionSink$(core.Object) { | |
| 977 _JsonEncoderSink(_sink, _toEncodable, _indent) { | |
| 978 this._sink = _sink; | |
| 979 this._toEncodable = _toEncodable; | |
| 980 this._indent = _indent; | |
| 981 this._isDone = false; | |
| 982 super.ChunkedConversionSink(); | |
| 983 } | |
| 984 add(o) { | |
| 985 if (this._isDone) { | |
| 986 throw new core.StateError("Only one call to add allowed"); | |
| 987 } | |
| 988 this._isDone = true; | |
| 989 let stringSink = this._sink.asStringSink(); | |
| 990 _JsonStringStringifier.printOn(o, stringSink, dart.as(this._toEncodable, d
art.throw_("Unimplemented type (dynamic) → dynamic")), this._indent); | |
| 991 stringSink.close(); | |
| 992 } | |
| 993 close() {} | |
| 994 } | |
| 995 class _JsonUtf8EncoderSink extends ChunkedConversionSink$(core.Object) { | |
| 996 _JsonUtf8EncoderSink(_sink, _toEncodable, _indent, _bufferSize) { | |
| 997 this._sink = _sink; | |
| 998 this._toEncodable = _toEncodable; | |
| 999 this._indent = _indent; | |
| 1000 this._bufferSize = _bufferSize; | |
| 1001 this._isDone = false; | |
| 1002 super.ChunkedConversionSink(); | |
| 1003 } | |
| 1004 _addChunk(chunk, start, end) { | |
| 1005 this._sink.addSlice(chunk, start, end, false); | |
| 1006 } | |
| 1007 add(object) { | |
| 1008 if (this._isDone) { | |
| 1009 throw new core.StateError("Only one call to add allowed"); | |
| 1010 } | |
| 1011 this._isDone = true; | |
| 1012 _JsonUtf8Stringifier.stringify(object, this._indent, dart.as(this._toEncod
able, dart.throw_("Unimplemented type (Object) → dynamic")), this._bufferSize, t
his._addChunk); | |
| 1013 this._sink.close(); | |
| 1014 } | |
| 1015 close() { | |
| 1016 if (!dart.notNull(this._isDone)) { | |
| 1017 this._isDone = true; | |
| 1018 this._sink.close(); | |
| 1019 } | |
| 1020 } | |
| 1021 } | |
| 1022 class JsonDecoder extends Converter$(core.String, core.Object) { | |
| 1023 JsonDecoder(reviver) { | |
| 1024 if (reviver === void 0) | |
| 1025 reviver = null; | |
| 1026 this._reviver = reviver; | |
| 1027 super.Converter(); | |
| 1028 } | |
| 1029 convert(input) { | |
| 1030 return _parseJson(input, this._reviver); | |
| 1031 } | |
| 1032 startChunkedConversion(sink) { | |
| 1033 return new _JsonDecoderSink(this._reviver, sink); | |
| 1034 } | |
| 1035 bind(stream) { | |
| 1036 return dart.as(super.bind(stream), async.Stream$(core.Object)); | |
| 1037 } | |
| 1038 } | |
| 1039 // Function _parseJson: (String, (dynamic, dynamic) → dynamic) → dynamic | |
| 1040 function _parseJson(source, reviver) { | |
| 1041 if (!(typeof source == string)) | |
| 1042 throw new core.ArgumentError(source); | |
| 1043 let parsed = null; | |
| 1044 try { | |
| 1045 parsed = JSON.parse(source); | |
| 1046 } catch (e) { | |
| 1047 throw new core.FormatException(String(e)); | |
| 1048 } | |
| 1049 | |
| 1050 if (reviver === null) { | |
| 1051 return _convertJsonToDartLazy(parsed); | |
| 1052 } else { | |
| 1053 return _convertJsonToDart(parsed, reviver); | |
| 1054 } | |
| 1055 } | |
| 1056 // Function _defaultToEncodable: (dynamic) → Object | |
| 1057 function _defaultToEncodable(object) { | |
| 1058 return dart.dinvoke(object, 'toJson'); | |
| 1059 } | |
| 1060 class _JsonStringifier extends dart.Object { | |
| 1061 _JsonStringifier(_toEncodable) { | |
| 1062 this._seen = new core.List(); | |
| 1063 this._toEncodable = dart.as(_toEncodable !== null ? _toEncodable : _defaul
tToEncodable, core.Function); | |
| 1064 } | |
| 1065 static hexDigit(x) { | |
| 1066 return x < 10 ? 48 + x : 87 + x; | |
| 1067 } | |
| 1068 writeStringContent(s) { | |
| 1069 let offset = 0; | |
| 1070 let length = s.length; | |
| 1071 for (let i = 0; i < length; i++) { | |
| 1072 let charCode = s.codeUnitAt(i); | |
| 1073 if (charCode > BACKSLASH) | |
| 1074 continue; | |
| 1075 if (charCode < 32) { | |
| 1076 if (i > offset) | |
| 1077 this.writeStringSlice(s, offset, i); | |
| 1078 offset = i + 1; | |
| 1079 this.writeCharCode(BACKSLASH); | |
| 1080 switch (charCode) { | |
| 1081 case BACKSPACE: | |
| 1082 this.writeCharCode(CHAR_b); | |
| 1083 break; | |
| 1084 case TAB: | |
| 1085 this.writeCharCode(CHAR_t); | |
| 1086 break; | |
| 1087 case NEWLINE: | |
| 1088 this.writeCharCode(CHAR_n); | |
| 1089 break; | |
| 1090 case FORM_FEED: | |
| 1091 this.writeCharCode(CHAR_f); | |
| 1092 break; | |
| 1093 case CARRIAGE_RETURN: | |
| 1094 this.writeCharCode(CHAR_r); | |
| 1095 break; | |
| 1096 default: | |
| 1097 this.writeCharCode(CHAR_u); | |
| 1098 this.writeCharCode(CHAR_0); | |
| 1099 this.writeCharCode(CHAR_0); | |
| 1100 this.writeCharCode(hexDigit(charCode >> 4 & 15)); | |
| 1101 this.writeCharCode(hexDigit(charCode & 15)); | |
| 1102 break; | |
| 1103 } | |
| 1104 } else if (dart.notNull(charCode === QUOTE) || dart.notNull(charCode ===
BACKSLASH)) { | |
| 1105 if (i > offset) | |
| 1106 this.writeStringSlice(s, offset, i); | |
| 1107 offset = i + 1; | |
| 1108 this.writeCharCode(BACKSLASH); | |
| 1109 this.writeCharCode(charCode); | |
| 1110 } | |
| 1111 } | |
| 1112 if (offset === 0) { | |
| 1113 this.writeString(s); | |
| 1114 } else if (offset < length) { | |
| 1115 this.writeStringSlice(s, offset, length); | |
| 1116 } | |
| 1117 } | |
| 1118 _checkCycle(object) { | |
| 1119 for (let i = 0; i < this._seen.length; i++) { | |
| 1120 if (core.identical(object, this._seen.get(i))) { | |
| 1121 throw new JsonCyclicError(object); | |
| 1122 } | |
| 1123 } | |
| 1124 this._seen.add(object); | |
| 1125 } | |
| 1126 _removeSeen(object) { | |
| 1127 dart.assert(!dart.notNull(this._seen.isEmpty)); | |
| 1128 dart.assert(core.identical(this._seen.last, object)); | |
| 1129 this._seen.removeLast(); | |
| 1130 } | |
| 1131 writeObject(object) { | |
| 1132 if (this.writeJsonValue(object)) | |
| 1133 return; | |
| 1134 this._checkCycle(object); | |
| 1135 try { | |
| 1136 let customJson = dart.dinvokef(this._toEncodable, object); | |
| 1137 if (!dart.notNull(this.writeJsonValue(customJson))) { | |
| 1138 throw new JsonUnsupportedObjectError(object); | |
| 1139 } | |
| 1140 this._removeSeen(object); | |
| 1141 } catch (e) { | |
| 1142 throw new JsonUnsupportedObjectError(object, {cause: e}); | |
| 1143 } | |
| 1144 | |
| 1145 } | |
| 1146 writeJsonValue(object) { | |
| 1147 if (dart.is(object, core.num)) { | |
| 1148 if (dart.throw_("Unimplemented PrefixExpression: !object.isFinite")) | |
| 1149 return false; | |
| 1150 this.writeNumber(dart.as(object, core.num)); | |
| 1151 return true; | |
| 1152 } else if (core.identical(object, true)) { | |
| 1153 this.writeString('true'); | |
| 1154 return true; | |
| 1155 } else if (core.identical(object, false)) { | |
| 1156 this.writeString('false'); | |
| 1157 return true; | |
| 1158 } else if (object === null) { | |
| 1159 this.writeString('null'); | |
| 1160 return true; | |
| 1161 } else if (typeof object == string) { | |
| 1162 this.writeString('"'); | |
| 1163 this.writeStringContent(dart.as(object, core.String)); | |
| 1164 this.writeString('"'); | |
| 1165 return true; | |
| 1166 } else if (dart.is(object, core.List)) { | |
| 1167 this._checkCycle(object); | |
| 1168 this.writeList(dart.as(object, core.List)); | |
| 1169 this._removeSeen(object); | |
| 1170 return true; | |
| 1171 } else if (dart.is(object, core.Map)) { | |
| 1172 this._checkCycle(object); | |
| 1173 this.writeMap(dart.as(object, core.Map$(core.String, core.Object))); | |
| 1174 this._removeSeen(object); | |
| 1175 return true; | |
| 1176 } else { | |
| 1177 return false; | |
| 1178 } | |
| 1179 } | |
| 1180 writeList(list) { | |
| 1181 this.writeString('['); | |
| 1182 if (list.length > 0) { | |
| 1183 this.writeObject(list.get(0)); | |
| 1184 for (let i = 1; i < list.length; i++) { | |
| 1185 this.writeString(','); | |
| 1186 this.writeObject(list.get(i)); | |
| 1187 } | |
| 1188 } | |
| 1189 this.writeString(']'); | |
| 1190 } | |
| 1191 writeMap(map) { | |
| 1192 this.writeString('{'); | |
| 1193 let separator = '"'; | |
| 1194 map.forEach(((key, value) => { | |
| 1195 this.writeString(separator); | |
| 1196 separator = ',"'; | |
| 1197 this.writeStringContent(key); | |
| 1198 this.writeString('":'); | |
| 1199 this.writeObject(value); | |
| 1200 }).bind(this)); | |
| 1201 this.writeString('}'); | |
| 1202 } | |
| 1203 } | |
| 1204 _JsonStringifier.BACKSPACE = 8; | |
| 1205 _JsonStringifier.TAB = 9; | |
| 1206 _JsonStringifier.NEWLINE = 10; | |
| 1207 _JsonStringifier.CARRIAGE_RETURN = 13; | |
| 1208 _JsonStringifier.FORM_FEED = 12; | |
| 1209 _JsonStringifier.QUOTE = 34; | |
| 1210 _JsonStringifier.CHAR_0 = 48; | |
| 1211 _JsonStringifier.BACKSLASH = 92; | |
| 1212 _JsonStringifier.CHAR_b = 98; | |
| 1213 _JsonStringifier.CHAR_f = 102; | |
| 1214 _JsonStringifier.CHAR_n = 110; | |
| 1215 _JsonStringifier.CHAR_r = 114; | |
| 1216 _JsonStringifier.CHAR_t = 116; | |
| 1217 _JsonStringifier.CHAR_u = 117; | |
| 1218 class _JsonPrettyPrintMixin extends dart.Object { | |
| 1219 _JsonPrettyPrintMixin() { | |
| 1220 this._indentLevel = 0; | |
| 1221 } | |
| 1222 writeList(list) { | |
| 1223 if (list.isEmpty) { | |
| 1224 this.writeString('[]'); | |
| 1225 } else { | |
| 1226 this.writeString('[\n'); | |
| 1227 this._indentLevel++; | |
| 1228 this.writeIndentation(this._indentLevel); | |
| 1229 this.writeObject(list.get(0)); | |
| 1230 for (let i = 1; i < list.length; i++) { | |
| 1231 this.writeString(',\n'); | |
| 1232 this.writeIndentation(this._indentLevel); | |
| 1233 this.writeObject(list.get(i)); | |
| 1234 } | |
| 1235 this.writeString('\n'); | |
| 1236 this._indentLevel--; | |
| 1237 this.writeIndentation(this._indentLevel); | |
| 1238 this.writeString(']'); | |
| 1239 } | |
| 1240 } | |
| 1241 writeMap(map) { | |
| 1242 if (map.isEmpty) { | |
| 1243 this.writeString('{}'); | |
| 1244 } else { | |
| 1245 this.writeString('{\n'); | |
| 1246 this._indentLevel++; | |
| 1247 let first = true; | |
| 1248 map.forEach(dart.as(((key, value) => { | |
| 1249 if (!dart.notNull(first)) { | |
| 1250 this.writeString(",\n"); | |
| 1251 } | |
| 1252 this.writeIndentation(this._indentLevel); | |
| 1253 this.writeString('"'); | |
| 1254 this.writeStringContent(key); | |
| 1255 this.writeString('": '); | |
| 1256 this.writeObject(value); | |
| 1257 first = false; | |
| 1258 }).bind(this), dart.throw_("Unimplemented type (dynamic, dynamic) → void
"))); | |
| 1259 this.writeString('\n'); | |
| 1260 this._indentLevel--; | |
| 1261 this.writeIndentation(this._indentLevel); | |
| 1262 this.writeString('}'); | |
| 1263 } | |
| 1264 } | |
| 1265 } | |
| 1266 class _JsonStringStringifier extends _JsonStringifier { | |
| 1267 _JsonStringStringifier(_sink, _toEncodable) { | |
| 1268 this._sink = _sink; | |
| 1269 super._JsonStringifier(dart.as(_toEncodable, dart.throw_("Unimplemented ty
pe (Object) → Object"))); | |
| 1270 } | |
| 1271 static stringify(object, toEncodable, indent) { | |
| 1272 let output = new core.StringBuffer(); | |
| 1273 printOn(object, output, toEncodable, indent); | |
| 1274 return output.toString(); | |
| 1275 } | |
| 1276 static printOn(object, output, toEncodable, indent) { | |
| 1277 let stringifier = null; | |
| 1278 if (indent === null) { | |
| 1279 stringifier = new _JsonStringStringifier(output, toEncodable); | |
| 1280 } else { | |
| 1281 stringifier = new _JsonStringStringifierPretty(output, toEncodable, inde
nt); | |
| 1282 } | |
| 1283 dart.dinvoke(stringifier, 'writeObject', object); | |
| 1284 } | |
| 1285 writeNumber(number) { | |
| 1286 this._sink.write(number.toString()); | |
| 1287 } | |
| 1288 writeString(string) { | |
| 1289 this._sink.write(string); | |
| 1290 } | |
| 1291 writeStringSlice(string, start, end) { | |
| 1292 this._sink.write(string.substring(start, end)); | |
| 1293 } | |
| 1294 writeCharCode(charCode) { | |
| 1295 this._sink.writeCharCode(charCode); | |
| 1296 } | |
| 1297 } | |
| 1298 class _JsonStringStringifierPretty extends dart.mixin(_JsonStringStringifier,
_JsonPrettyPrintMixin) { | |
| 1299 _JsonStringStringifierPretty(sink, toEncodable, _indent) { | |
| 1300 this._indent = _indent; | |
| 1301 super._JsonStringStringifier(sink, toEncodable); | |
| 1302 } | |
| 1303 writeIndentation(count) { | |
| 1304 for (let i = 0; i < count; i++) | |
| 1305 this.writeString(this._indent); | |
| 1306 } | |
| 1307 } | |
| 1308 class _JsonUtf8Stringifier extends _JsonStringifier { | |
| 1309 _JsonUtf8Stringifier(toEncodable, bufferSize, addChunk) { | |
| 1310 this.addChunk = addChunk; | |
| 1311 this.bufferSize = bufferSize; | |
| 1312 this.buffer = new typed_data.Uint8List(bufferSize); | |
| 1313 this.index = 0; | |
| 1314 super._JsonStringifier(dart.as(toEncodable, dart.throw_("Unimplemented typ
e (Object) → Object"))); | |
| 1315 } | |
| 1316 static stringify(object, indent, toEncodableFunction, bufferSize, addChunk)
{ | |
| 1317 let stringifier = null; | |
| 1318 if (indent !== null) { | |
| 1319 stringifier = new _JsonUtf8StringifierPretty(toEncodableFunction, indent
, bufferSize, addChunk); | |
| 1320 } else { | |
| 1321 stringifier = new _JsonUtf8Stringifier(toEncodableFunction, bufferSize,
addChunk); | |
| 1322 } | |
| 1323 stringifier.writeObject(object); | |
| 1324 stringifier.flush(); | |
| 1325 } | |
| 1326 flush() { | |
| 1327 if (this.index > 0) { | |
| 1328 dart.dinvokef(this.addChunk, this.buffer, 0, this.index); | |
| 1329 } | |
| 1330 this.buffer = null; | |
| 1331 this.index = 0; | |
| 1332 } | |
| 1333 writeNumber(number) { | |
| 1334 this.writeAsciiString(number.toString()); | |
| 1335 } | |
| 1336 writeAsciiString(string) { | |
| 1337 for (let i = 0; i < string.length; i++) { | |
| 1338 let char = string.codeUnitAt(i); | |
| 1339 dart.assert(char <= 127); | |
| 1340 this.writeByte(char); | |
| 1341 } | |
| 1342 } | |
| 1343 writeString(string) { | |
| 1344 this.writeStringSlice(string, 0, string.length); | |
| 1345 } | |
| 1346 writeStringSlice(string, start, end) { | |
| 1347 for (let i = start; i < end; i++) { | |
| 1348 let char = string.codeUnitAt(i); | |
| 1349 if (char <= 127) { | |
| 1350 this.writeByte(char); | |
| 1351 } else { | |
| 1352 if (dart.notNull((char & 64512) === 55296) && dart.notNull(i + 1 < end
)) { | |
| 1353 let nextChar = string.codeUnitAt(i + 1); | |
| 1354 if ((nextChar & 64512) === 56320) { | |
| 1355 char = 65536 + ((char & 1023) << 10) + (nextChar & 1023); | |
| 1356 this.writeFourByteCharCode(char); | |
| 1357 i++; | |
| 1358 continue; | |
| 1359 } | |
| 1360 } | |
| 1361 this.writeMultiByteCharCode(char); | |
| 1362 } | |
| 1363 } | |
| 1364 } | |
| 1365 writeCharCode(charCode) { | |
| 1366 if (charCode <= 127) { | |
| 1367 this.writeByte(charCode); | |
| 1368 return; | |
| 1369 } | |
| 1370 this.writeMultiByteCharCode(charCode); | |
| 1371 } | |
| 1372 writeMultiByteCharCode(charCode) { | |
| 1373 if (charCode <= 2047) { | |
| 1374 this.writeByte(192 | charCode >> 6); | |
| 1375 this.writeByte(128 | charCode & 63); | |
| 1376 return; | |
| 1377 } | |
| 1378 if (charCode <= 65535) { | |
| 1379 this.writeByte(224 | charCode >> 12); | |
| 1380 this.writeByte(128 | charCode >> 6 & 63); | |
| 1381 this.writeByte(128 | charCode & 63); | |
| 1382 return; | |
| 1383 } | |
| 1384 this.writeFourByteCharCode(charCode); | |
| 1385 } | |
| 1386 writeFourByteCharCode(charCode) { | |
| 1387 dart.assert(charCode <= 1114111); | |
| 1388 this.writeByte(240 | charCode >> 18); | |
| 1389 this.writeByte(128 | charCode >> 12 & 63); | |
| 1390 this.writeByte(128 | charCode >> 6 & 63); | |
| 1391 this.writeByte(128 | charCode & 63); | |
| 1392 } | |
| 1393 writeByte(byte) { | |
| 1394 dart.assert(byte <= 255); | |
| 1395 if (this.index === this.buffer.length) { | |
| 1396 dart.dinvokef(this.addChunk, this.buffer, 0, this.index); | |
| 1397 this.buffer = new typed_data.Uint8List(this.bufferSize); | |
| 1398 this.index = 0; | |
| 1399 } | |
| 1400 this.buffer.set(this.index++, byte); | |
| 1401 } | |
| 1402 } | |
| 1403 class _JsonUtf8StringifierPretty extends dart.mixin(_JsonUtf8Stringifier, _Jso
nPrettyPrintMixin) { | |
| 1404 _JsonUtf8StringifierPretty(toEncodableFunction, indent, bufferSize, addChunk
) { | |
| 1405 this.indent = indent; | |
| 1406 super._JsonUtf8Stringifier(toEncodableFunction, dart.as(bufferSize, core.i
nt), dart.as(addChunk, core.Function)); | |
| 1407 } | |
| 1408 writeIndentation(count) { | |
| 1409 let indent = this.indent; | |
| 1410 let indentLength = indent.length; | |
| 1411 if (indentLength === 1) { | |
| 1412 let char = indent.get(0); | |
| 1413 while (count > 0) { | |
| 1414 this.writeByte(char); | |
| 1415 count = 1; | |
| 1416 } | |
| 1417 return; | |
| 1418 } | |
| 1419 while (count > 0) { | |
| 1420 count--; | |
| 1421 let end = this.index + indentLength; | |
| 1422 if (end <= this.buffer.length) { | |
| 1423 this.buffer.setRange(this.index, end, indent); | |
| 1424 this.index = end; | |
| 1425 } else { | |
| 1426 for (let i = 0; i < indentLength; i++) { | |
| 1427 this.writeByte(indent.get(i)); | |
| 1428 } | |
| 1429 } | |
| 1430 } | |
| 1431 } | |
| 1432 } | |
| 1433 let LATIN1 = new Latin1Codec(); | |
| 1434 let _LATIN1_MASK = 255; | |
| 1435 class Latin1Codec extends Encoding { | |
| 1436 Latin1Codec(opt$) { | |
| 1437 let allowInvalid = opt$.allowInvalid === void 0 ? false : opt$.allowInvali
d; | |
| 1438 this._allowInvalid = allowInvalid; | |
| 1439 super.Encoding(); | |
| 1440 } | |
| 1441 get name() { | |
| 1442 return "iso-8859-1"; | |
| 1443 } | |
| 1444 decode(bytes, opt$) { | |
| 1445 let allowInvalid = opt$.allowInvalid === void 0 ? null : opt$.allowInvalid
; | |
| 1446 if (allowInvalid === null) | |
| 1447 allowInvalid = this._allowInvalid; | |
| 1448 if (allowInvalid) { | |
| 1449 return new Latin1Decoder({allowInvalid: true}).convert(bytes); | |
| 1450 } else { | |
| 1451 return new Latin1Decoder({allowInvalid: false}).convert(bytes); | |
| 1452 } | |
| 1453 } | |
| 1454 get encoder() { | |
| 1455 return new Latin1Encoder(); | |
| 1456 } | |
| 1457 get decoder() { | |
| 1458 return this._allowInvalid ? new Latin1Decoder({allowInvalid: true}) : new
Latin1Decoder({allowInvalid: false}); | |
| 1459 } | |
| 1460 } | |
| 1461 class Latin1Encoder extends _UnicodeSubsetEncoder { | |
| 1462 Latin1Encoder() { | |
| 1463 super._UnicodeSubsetEncoder(_LATIN1_MASK); | |
| 1464 } | |
| 1465 } | |
| 1466 class Latin1Decoder extends _UnicodeSubsetDecoder { | |
| 1467 Latin1Decoder(opt$) { | |
| 1468 let allowInvalid = opt$.allowInvalid === void 0 ? false : opt$.allowInvali
d; | |
| 1469 super._UnicodeSubsetDecoder(allowInvalid, _LATIN1_MASK); | |
| 1470 } | |
| 1471 startChunkedConversion(sink) { | |
| 1472 let stringSink = null; | |
| 1473 if (dart.is(sink, StringConversionSink)) { | |
| 1474 stringSink = sink; | |
| 1475 } else { | |
| 1476 stringSink = new StringConversionSink.from(sink); | |
| 1477 } | |
| 1478 if (!dart.notNull(this._allowInvalid)) | |
| 1479 return new _Latin1DecoderSink(stringSink); | |
| 1480 return new _Latin1AllowInvalidDecoderSink(stringSink); | |
| 1481 } | |
| 1482 } | |
| 1483 class _Latin1DecoderSink extends ByteConversionSinkBase { | |
| 1484 _Latin1DecoderSink(_sink) { | |
| 1485 this._sink = _sink; | |
| 1486 super.ByteConversionSinkBase(); | |
| 1487 } | |
| 1488 close() { | |
| 1489 this._sink.close(); | |
| 1490 } | |
| 1491 add(source) { | |
| 1492 this.addSlice(source, 0, source.length, false); | |
| 1493 } | |
| 1494 _addSliceToSink(source, start, end, isLast) { | |
| 1495 this._sink.add(new core.String.fromCharCodes(source, start, end)); | |
| 1496 if (isLast) | |
| 1497 this.close(); | |
| 1498 } | |
| 1499 addSlice(source, start, end, isLast) { | |
| 1500 core.RangeError.checkValidRange(start, end, source.length); | |
| 1501 for (let i = start; i < end; i++) { | |
| 1502 let char = source.get(i); | |
| 1503 if (dart.notNull(char > _LATIN1_MASK) || dart.notNull(char < 0)) { | |
| 1504 throw new core.FormatException("Source contains non-Latin-1 characters
."); | |
| 1505 } | |
| 1506 } | |
| 1507 if (start < end) { | |
| 1508 this._addSliceToSink(source, start, end, isLast); | |
| 1509 } | |
| 1510 if (isLast) { | |
| 1511 this.close(); | |
| 1512 } | |
| 1513 } | |
| 1514 } | |
| 1515 class _Latin1AllowInvalidDecoderSink extends _Latin1DecoderSink { | |
| 1516 _Latin1AllowInvalidDecoderSink(sink) { | |
| 1517 super._Latin1DecoderSink(sink); | |
| 1518 } | |
| 1519 addSlice(source, start, end, isLast) { | |
| 1520 core.RangeError.checkValidRange(start, end, source.length); | |
| 1521 for (let i = start; i < end; i++) { | |
| 1522 let char = source.get(i); | |
| 1523 if (dart.notNull(char > _LATIN1_MASK) || dart.notNull(char < 0)) { | |
| 1524 if (i > start) | |
| 1525 this._addSliceToSink(source, start, i, false); | |
| 1526 this._addSliceToSink(dart.as(/* Unimplemented const */new List.from([6
5533]), core.List$(core.int)), 0, 1, false); | |
| 1527 start = i + 1; | |
| 1528 } | |
| 1529 } | |
| 1530 if (start < end) { | |
| 1531 this._addSliceToSink(source, start, end, isLast); | |
| 1532 } | |
| 1533 if (isLast) { | |
| 1534 this.close(); | |
| 1535 } | |
| 1536 } | |
| 1537 } | |
| 1538 class LineSplitter extends Converter$(core.String, core.List$(core.String)) { | |
| 1539 LineSplitter() { | |
| 1540 super.Converter(); | |
| 1541 } | |
| 1542 convert(data) { | |
| 1543 let lines = new core.List(); | |
| 1544 _LineSplitterSink._addSlice(data, 0, data.length, true, lines.add); | |
| 1545 return lines; | |
| 1546 } | |
| 1547 startChunkedConversion(sink) { | |
| 1548 if (!dart.is(sink, StringConversionSink)) { | |
| 1549 sink = new StringConversionSink.from(sink); | |
| 1550 } | |
| 1551 return new _LineSplitterSink(dart.as(sink, StringConversionSink)); | |
| 1552 } | |
| 1553 } | |
| 1554 class _LineSplitterSink extends StringConversionSinkBase { | |
| 1555 _LineSplitterSink(_sink) { | |
| 1556 this._sink = _sink; | |
| 1557 this._carry = null; | |
| 1558 super.StringConversionSinkBase(); | |
| 1559 } | |
| 1560 addSlice(chunk, start, end, isLast) { | |
| 1561 if (this._carry !== null) { | |
| 1562 chunk = core.String['+'](this._carry, chunk.substring(start, end)); | |
| 1563 start = 0; | |
| 1564 end = chunk.length; | |
| 1565 this._carry = null; | |
| 1566 } | |
| 1567 this._carry = _addSlice(chunk, start, end, isLast, this._sink.add); | |
| 1568 if (isLast) | |
| 1569 this._sink.close(); | |
| 1570 } | |
| 1571 close() { | |
| 1572 this.addSlice('', 0, 0, true); | |
| 1573 } | |
| 1574 static _addSlice(chunk, start, end, isLast, adder) { | |
| 1575 let pos = start; | |
| 1576 while (pos < end) { | |
| 1577 let skip = 0; | |
| 1578 let char = chunk.codeUnitAt(pos); | |
| 1579 if (char === _LF) { | |
| 1580 skip = 1; | |
| 1581 } else if (char === _CR) { | |
| 1582 skip = 1; | |
| 1583 if (pos + 1 < end) { | |
| 1584 if (chunk.codeUnitAt(pos + 1) === _LF) { | |
| 1585 skip = 2; | |
| 1586 } | |
| 1587 } else if (!dart.notNull(isLast)) { | |
| 1588 return chunk.substring(start, end); | |
| 1589 } | |
| 1590 } | |
| 1591 if (skip > 0) { | |
| 1592 adder(chunk.substring(start, pos)); | |
| 1593 start = pos = pos + skip; | |
| 1594 } else { | |
| 1595 pos++; | |
| 1596 } | |
| 1597 } | |
| 1598 if (pos !== start) { | |
| 1599 let carry = chunk.substring(start, pos); | |
| 1600 if (isLast) { | |
| 1601 adder(carry); | |
| 1602 } else { | |
| 1603 return carry; | |
| 1604 } | |
| 1605 } | |
| 1606 return null; | |
| 1607 } | |
| 1608 } | |
| 1609 _LineSplitterSink._LF = 10; | |
| 1610 _LineSplitterSink._CR = 13; | |
| 1611 class StringConversionSink extends ChunkedConversionSink$(core.String) { | |
| 1612 StringConversionSink() { | |
| 1613 super.ChunkedConversionSink(); | |
| 1614 } | |
| 1615 StringConversionSink$withCallback(callback) { | |
| 1616 return new _StringCallbackSink(callback); | |
| 1617 } | |
| 1618 StringConversionSink$from(sink) { | |
| 1619 return new _StringAdapterSink(sink); | |
| 1620 } | |
| 1621 StringConversionSink$fromStringSink(sink) { | |
| 1622 return new _StringSinkConversionSink(sink); | |
| 1623 } | |
| 1624 } | |
| 1625 dart.defineNamedConstructor(StringConversionSink, 'withCallback'); | |
| 1626 dart.defineNamedConstructor(StringConversionSink, 'from'); | |
| 1627 dart.defineNamedConstructor(StringConversionSink, 'fromStringSink'); | |
| 1628 class ClosableStringSink extends core.StringSink { | |
| 1629 ClosableStringSink$fromStringSink(sink, onClose) { | |
| 1630 return new _ClosableStringSink(sink, onClose); | |
| 1631 } | |
| 1632 } | |
| 1633 dart.defineNamedConstructor(ClosableStringSink, 'fromStringSink'); | |
| 1634 class _ClosableStringSink extends dart.Object { | |
| 1635 _ClosableStringSink(_sink, _callback) { | |
| 1636 this._sink = _sink; | |
| 1637 this._callback = _callback; | |
| 1638 } | |
| 1639 close() { | |
| 1640 return this._callback(); | |
| 1641 } | |
| 1642 writeCharCode(charCode) { | |
| 1643 return this._sink.writeCharCode(charCode); | |
| 1644 } | |
| 1645 write(o) { | |
| 1646 return this._sink.write(o); | |
| 1647 } | |
| 1648 writeln(o) { | |
| 1649 if (o === void 0) | |
| 1650 o = ""; | |
| 1651 return this._sink.writeln(o); | |
| 1652 } | |
| 1653 writeAll(objects, separator) { | |
| 1654 if (separator === void 0) | |
| 1655 separator = ""; | |
| 1656 return this._sink.writeAll(objects, separator); | |
| 1657 } | |
| 1658 } | |
| 1659 class _StringConversionSinkAsStringSinkAdapter extends dart.Object { | |
| 1660 _StringConversionSinkAsStringSinkAdapter(_chunkedSink) { | |
| 1661 this._chunkedSink = _chunkedSink; | |
| 1662 this._buffer = new core.StringBuffer(); | |
| 1663 } | |
| 1664 close() { | |
| 1665 if (this._buffer.isNotEmpty) | |
| 1666 this._flush(); | |
| 1667 this._chunkedSink.close(); | |
| 1668 } | |
| 1669 writeCharCode(charCode) { | |
| 1670 this._buffer.writeCharCode(charCode); | |
| 1671 if (this._buffer.length['>'](_MIN_STRING_SIZE)) | |
| 1672 this._flush(); | |
| 1673 } | |
| 1674 write(o) { | |
| 1675 if (this._buffer.isNotEmpty) | |
| 1676 this._flush(); | |
| 1677 let str = o.toString(); | |
| 1678 this._chunkedSink.add(o.toString()); | |
| 1679 } | |
| 1680 writeln(o) { | |
| 1681 if (o === void 0) | |
| 1682 o = ""; | |
| 1683 this._buffer.writeln(o); | |
| 1684 if (this._buffer.length['>'](_MIN_STRING_SIZE)) | |
| 1685 this._flush(); | |
| 1686 } | |
| 1687 writeAll(objects, separator) { | |
| 1688 if (separator === void 0) | |
| 1689 separator = ""; | |
| 1690 if (this._buffer.isNotEmpty) | |
| 1691 this._flush(); | |
| 1692 let iterator = objects.iterator; | |
| 1693 if (!dart.notNull(iterator.moveNext())) | |
| 1694 return; | |
| 1695 if (separator.isEmpty) { | |
| 1696 do { | |
| 1697 this._chunkedSink.add(dart.as(dart.dinvoke(iterator.current, 'toString
'), core.String)); | |
| 1698 } while (iterator.moveNext()); | |
| 1699 } else { | |
| 1700 this._chunkedSink.add(dart.as(dart.dinvoke(iterator.current, 'toString')
, core.String)); | |
| 1701 while (iterator.moveNext()) { | |
| 1702 this.write(separator); | |
| 1703 this._chunkedSink.add(dart.as(dart.dinvoke(iterator.current, 'toString
'), core.String)); | |
| 1704 } | |
| 1705 } | |
| 1706 } | |
| 1707 _flush() { | |
| 1708 let accumulated = this._buffer.toString(); | |
| 1709 this._buffer.clear(); | |
| 1710 this._chunkedSink.add(accumulated); | |
| 1711 } | |
| 1712 } | |
| 1713 _StringConversionSinkAsStringSinkAdapter._MIN_STRING_SIZE = 16; | |
| 1714 class StringConversionSinkBase extends StringConversionSinkMixin { | |
| 1715 } | |
| 1716 class StringConversionSinkMixin extends dart.Object { | |
| 1717 add(str) { | |
| 1718 return this.addSlice(str, 0, str.length, false); | |
| 1719 } | |
| 1720 asUtf8Sink(allowMalformed) { | |
| 1721 return new _Utf8ConversionSink(this, allowMalformed); | |
| 1722 } | |
| 1723 asStringSink() { | |
| 1724 return new _StringConversionSinkAsStringSinkAdapter(this); | |
| 1725 } | |
| 1726 } | |
| 1727 class _StringSinkConversionSink extends StringConversionSinkBase { | |
| 1728 _StringSinkConversionSink(_stringSink) { | |
| 1729 this._stringSink = _stringSink; | |
| 1730 super.StringConversionSinkBase(); | |
| 1731 } | |
| 1732 close() {} | |
| 1733 addSlice(str, start, end, isLast) { | |
| 1734 if (dart.notNull(start !== 0) || dart.notNull(end !== str.length)) { | |
| 1735 for (let i = start; i < end; i++) { | |
| 1736 this._stringSink.writeCharCode(str.codeUnitAt(i)); | |
| 1737 } | |
| 1738 } else { | |
| 1739 this._stringSink.write(str); | |
| 1740 } | |
| 1741 if (isLast) | |
| 1742 this.close(); | |
| 1743 } | |
| 1744 add(str) { | |
| 1745 return this._stringSink.write(str); | |
| 1746 } | |
| 1747 asUtf8Sink(allowMalformed) { | |
| 1748 return new _Utf8StringSinkAdapter(this, this._stringSink, allowMalformed); | |
| 1749 } | |
| 1750 asStringSink() { | |
| 1751 return new ClosableStringSink.fromStringSink(this._stringSink, this.close)
; | |
| 1752 } | |
| 1753 } | |
| 1754 class _StringCallbackSink extends _StringSinkConversionSink { | |
| 1755 _StringCallbackSink(_callback) { | |
| 1756 this._callback = _callback; | |
| 1757 super._StringSinkConversionSink(new core.StringBuffer()); | |
| 1758 } | |
| 1759 close() { | |
| 1760 let buffer = dart.as(this._stringSink, core.StringBuffer); | |
| 1761 let accumulated = buffer.toString(); | |
| 1762 buffer.clear(); | |
| 1763 this._callback(accumulated); | |
| 1764 } | |
| 1765 asUtf8Sink(allowMalformed) { | |
| 1766 return new _Utf8StringSinkAdapter(this, this._stringSink, allowMalformed); | |
| 1767 } | |
| 1768 } | |
| 1769 class _StringAdapterSink extends StringConversionSinkBase { | |
| 1770 _StringAdapterSink(_sink) { | |
| 1771 this._sink = _sink; | |
| 1772 super.StringConversionSinkBase(); | |
| 1773 } | |
| 1774 add(str) { | |
| 1775 return this._sink.add(str); | |
| 1776 } | |
| 1777 addSlice(str, start, end, isLast) { | |
| 1778 if (dart.notNull(start === 0) && dart.notNull(end === str.length)) { | |
| 1779 this.add(str); | |
| 1780 } else { | |
| 1781 this.add(str.substring(start, end)); | |
| 1782 } | |
| 1783 if (isLast) | |
| 1784 this.close(); | |
| 1785 } | |
| 1786 close() { | |
| 1787 return this._sink.close(); | |
| 1788 } | |
| 1789 } | |
| 1790 class _Utf8StringSinkAdapter extends ByteConversionSink { | |
| 1791 _Utf8StringSinkAdapter(_sink, stringSink, allowMalformed) { | |
| 1792 this._sink = _sink; | |
| 1793 this._decoder = new _Utf8Decoder(stringSink, allowMalformed); | |
| 1794 super.ByteConversionSink(); | |
| 1795 } | |
| 1796 close() { | |
| 1797 this._decoder.close(); | |
| 1798 if (this._sink !== null) | |
| 1799 this._sink.close(); | |
| 1800 } | |
| 1801 add(chunk) { | |
| 1802 this.addSlice(chunk, 0, chunk.length, false); | |
| 1803 } | |
| 1804 addSlice(codeUnits, startIndex, endIndex, isLast) { | |
| 1805 this._decoder.convert(codeUnits, startIndex, endIndex); | |
| 1806 if (isLast) | |
| 1807 this.close(); | |
| 1808 } | |
| 1809 } | |
| 1810 class _Utf8ConversionSink extends ByteConversionSink { | |
| 1811 _Utf8ConversionSink(sink, allowMalformed) { | |
| 1812 this._Utf8ConversionSink$_(sink, new core.StringBuffer(), allowMalformed); | |
| 1813 } | |
| 1814 _Utf8ConversionSink$_(_chunkedSink, stringBuffer, allowMalformed) { | |
| 1815 this._chunkedSink = _chunkedSink; | |
| 1816 this._decoder = new _Utf8Decoder(stringBuffer, allowMalformed); | |
| 1817 this._buffer = stringBuffer; | |
| 1818 super.ByteConversionSink(); | |
| 1819 } | |
| 1820 close() { | |
| 1821 this._decoder.close(); | |
| 1822 if (this._buffer.isNotEmpty) { | |
| 1823 let accumulated = this._buffer.toString(); | |
| 1824 this._buffer.clear(); | |
| 1825 this._chunkedSink.addSlice(accumulated, 0, accumulated.length, true); | |
| 1826 } else { | |
| 1827 this._chunkedSink.close(); | |
| 1828 } | |
| 1829 } | |
| 1830 add(chunk) { | |
| 1831 this.addSlice(chunk, 0, chunk.length, false); | |
| 1832 } | |
| 1833 addSlice(chunk, startIndex, endIndex, isLast) { | |
| 1834 this._decoder.convert(chunk, startIndex, endIndex); | |
| 1835 if (this._buffer.isNotEmpty) { | |
| 1836 let accumulated = this._buffer.toString(); | |
| 1837 this._chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast); | |
| 1838 this._buffer.clear(); | |
| 1839 return; | |
| 1840 } | |
| 1841 if (isLast) | |
| 1842 this.close(); | |
| 1843 } | |
| 1844 } | |
| 1845 dart.defineNamedConstructor(_Utf8ConversionSink, '_'); | |
| 1846 let UNICODE_REPLACEMENT_CHARACTER_RUNE = 65533; | |
| 1847 let UNICODE_BOM_CHARACTER_RUNE = 65279; | |
| 1848 let UTF8 = new Utf8Codec(); | |
| 1849 class Utf8Codec extends Encoding { | |
| 1850 Utf8Codec(opt$) { | |
| 1851 let allowMalformed = opt$.allowMalformed === void 0 ? false : opt$.allowMa
lformed; | |
| 1852 this._allowMalformed = allowMalformed; | |
| 1853 super.Encoding(); | |
| 1854 } | |
| 1855 get name() { | |
| 1856 return "utf-8"; | |
| 1857 } | |
| 1858 decode(codeUnits, opt$) { | |
| 1859 let allowMalformed = opt$.allowMalformed === void 0 ? null : opt$.allowMal
formed; | |
| 1860 if (allowMalformed === null) | |
| 1861 allowMalformed = this._allowMalformed; | |
| 1862 return new Utf8Decoder({allowMalformed: allowMalformed}).convert(codeUnits
); | |
| 1863 } | |
| 1864 get encoder() { | |
| 1865 return new Utf8Encoder(); | |
| 1866 } | |
| 1867 get decoder() { | |
| 1868 return new Utf8Decoder({allowMalformed: this._allowMalformed}); | |
| 1869 } | |
| 1870 } | |
| 1871 class Utf8Encoder extends Converter$(core.String, core.List$(core.int)) { | |
| 1872 Utf8Encoder() { | |
| 1873 super.Converter(); | |
| 1874 } | |
| 1875 convert(string, start, end) { | |
| 1876 if (start === void 0) | |
| 1877 start = 0; | |
| 1878 if (end === void 0) | |
| 1879 end = null; | |
| 1880 let stringLength = string.length; | |
| 1881 core.RangeError.checkValidRange(start, end, stringLength); | |
| 1882 if (end === null) | |
| 1883 end = stringLength; | |
| 1884 let length = end - start; | |
| 1885 if (length === 0) | |
| 1886 return new typed_data.Uint8List(0); | |
| 1887 let encoder = new _Utf8Encoder.withBufferSize(length * 3); | |
| 1888 let endPosition = encoder._fillBuffer(string, start, end); | |
| 1889 dart.assert(endPosition >= end - 1); | |
| 1890 if (endPosition !== end) { | |
| 1891 let lastCodeUnit = string.codeUnitAt(end - 1); | |
| 1892 dart.assert(_isLeadSurrogate(lastCodeUnit)); | |
| 1893 let wasCombined = encoder._writeSurrogate(lastCodeUnit, 0); | |
| 1894 dart.assert(!dart.notNull(wasCombined)); | |
| 1895 } | |
| 1896 return encoder._buffer.sublist(0, encoder._bufferIndex); | |
| 1897 } | |
| 1898 startChunkedConversion(sink) { | |
| 1899 if (!dart.is(sink, ByteConversionSink)) { | |
| 1900 sink = new ByteConversionSink.from(sink); | |
| 1901 } | |
| 1902 return new _Utf8EncoderSink(dart.as(sink, ByteConversionSink)); | |
| 1903 } | |
| 1904 bind(stream) { | |
| 1905 return dart.as(super.bind(stream), async.Stream$(core.List$(core.int))); | |
| 1906 } | |
| 1907 } | |
| 1908 class _Utf8Encoder extends dart.Object { | |
| 1909 _Utf8Encoder() { | |
| 1910 this._Utf8Encoder$withBufferSize(dart.as(_DEFAULT_BYTE_BUFFER_SIZE, core.i
nt)); | |
| 1911 } | |
| 1912 _Utf8Encoder$withBufferSize(bufferSize) { | |
| 1913 this._buffer = _createBuffer(bufferSize); | |
| 1914 this._carry = 0; | |
| 1915 this._bufferIndex = 0; | |
| 1916 } | |
| 1917 static _createBuffer(size) { | |
| 1918 return new typed_data.Uint8List(size); | |
| 1919 } | |
| 1920 _writeSurrogate(leadingSurrogate, nextCodeUnit) { | |
| 1921 if (_isTailSurrogate(nextCodeUnit)) { | |
| 1922 let rune = _combineSurrogatePair(leadingSurrogate, nextCodeUnit); | |
| 1923 dart.assert(rune > _THREE_BYTE_LIMIT); | |
| 1924 dart.assert(rune <= _FOUR_BYTE_LIMIT); | |
| 1925 this._buffer.set(this._bufferIndex++, 240 | rune >> 18); | |
| 1926 this._buffer.set(this._bufferIndex++, 128 | rune >> 12 & 63); | |
| 1927 this._buffer.set(this._bufferIndex++, 128 | rune >> 6 & 63); | |
| 1928 this._buffer.set(this._bufferIndex++, 128 | rune & 63); | |
| 1929 return true; | |
| 1930 } else { | |
| 1931 this._buffer.set(this._bufferIndex++, 224 | leadingSurrogate >> 12); | |
| 1932 this._buffer.set(this._bufferIndex++, 128 | leadingSurrogate >> 6 & 63); | |
| 1933 this._buffer.set(this._bufferIndex++, 128 | leadingSurrogate & 63); | |
| 1934 return false; | |
| 1935 } | |
| 1936 } | |
| 1937 _fillBuffer(str, start, end) { | |
| 1938 if (dart.notNull(start !== end) && dart.notNull(_isLeadSurrogate(str.codeU
nitAt(end - 1)))) { | |
| 1939 end--; | |
| 1940 } | |
| 1941 let stringIndex = null; | |
| 1942 for (stringIndex = start; stringIndex < end; stringIndex++) { | |
| 1943 let codeUnit = str.codeUnitAt(stringIndex); | |
| 1944 if (codeUnit <= _ONE_BYTE_LIMIT) { | |
| 1945 if (this._bufferIndex >= this._buffer.length) | |
| 1946 break; | |
| 1947 this._buffer.set(this._bufferIndex++, codeUnit); | |
| 1948 } else if (_isLeadSurrogate(codeUnit)) { | |
| 1949 if (this._bufferIndex + 3 >= this._buffer.length) | |
| 1950 break; | |
| 1951 let nextCodeUnit = str.codeUnitAt(stringIndex + 1); | |
| 1952 let wasCombined = this._writeSurrogate(codeUnit, nextCodeUnit); | |
| 1953 if (wasCombined) | |
| 1954 stringIndex++; | |
| 1955 } else { | |
| 1956 let rune = codeUnit; | |
| 1957 if (rune <= _TWO_BYTE_LIMIT) { | |
| 1958 if (this._bufferIndex + 1 >= this._buffer.length) | |
| 1959 break; | |
| 1960 this._buffer.set(this._bufferIndex++, 192 | rune >> 6); | |
| 1961 this._buffer.set(this._bufferIndex++, 128 | rune & 63); | |
| 1962 } else { | |
| 1963 dart.assert(rune <= _THREE_BYTE_LIMIT); | |
| 1964 if (this._bufferIndex + 2 >= this._buffer.length) | |
| 1965 break; | |
| 1966 this._buffer.set(this._bufferIndex++, 224 | rune >> 12); | |
| 1967 this._buffer.set(this._bufferIndex++, 128 | rune >> 6 & 63); | |
| 1968 this._buffer.set(this._bufferIndex++, 128 | rune & 63); | |
| 1969 } | |
| 1970 } | |
| 1971 } | |
| 1972 return stringIndex; | |
| 1973 } | |
| 1974 } | |
| 1975 dart.defineNamedConstructor(_Utf8Encoder, 'withBufferSize'); | |
| 1976 _Utf8Encoder._DEFAULT_BYTE_BUFFER_SIZE = 1024; | |
| 1977 class _Utf8EncoderSink extends dart.mixin(_Utf8Encoder, StringConversionSinkMi
xin) { | |
| 1978 _Utf8EncoderSink(_sink) { | |
| 1979 this._sink = _sink; | |
| 1980 super._Utf8Encoder(); | |
| 1981 } | |
| 1982 close() { | |
| 1983 if (this._carry !== 0) { | |
| 1984 this.addSlice("", 0, 0, true); | |
| 1985 return; | |
| 1986 } | |
| 1987 this._sink.close(); | |
| 1988 } | |
| 1989 addSlice(str, start, end, isLast) { | |
| 1990 this._bufferIndex = 0; | |
| 1991 if (dart.notNull(start === end) && dart.notNull(!dart.notNull(isLast))) { | |
| 1992 return; | |
| 1993 } | |
| 1994 if (this._carry !== 0) { | |
| 1995 let nextCodeUnit = 0; | |
| 1996 if (start !== end) { | |
| 1997 nextCodeUnit = str.codeUnitAt(start); | |
| 1998 } else { | |
| 1999 dart.assert(isLast); | |
| 2000 } | |
| 2001 let wasCombined = this._writeSurrogate(this._carry, nextCodeUnit); | |
| 2002 dart.assert(dart.notNull(!dart.notNull(wasCombined)) || dart.notNull(sta
rt !== end)); | |
| 2003 if (wasCombined) | |
| 2004 start++; | |
| 2005 this._carry = 0; | |
| 2006 } | |
| 2007 do { | |
| 2008 start = this._fillBuffer(str, start, end); | |
| 2009 let isLastSlice = dart.notNull(isLast) && dart.notNull(start === end); | |
| 2010 if (dart.notNull(start === end - 1) && dart.notNull(_isLeadSurrogate(str
.codeUnitAt(start)))) { | |
| 2011 if (dart.notNull(isLast) && dart.notNull(this._bufferIndex < this._buf
fer.length - 3)) { | |
| 2012 let hasBeenCombined = this._writeSurrogate(str.codeUnitAt(start), 0)
; | |
| 2013 dart.assert(!dart.notNull(hasBeenCombined)); | |
| 2014 } else { | |
| 2015 this._carry = str.codeUnitAt(start); | |
| 2016 } | |
| 2017 start++; | |
| 2018 } | |
| 2019 this._sink.addSlice(this._buffer, 0, this._bufferIndex, isLastSlice); | |
| 2020 this._bufferIndex = 0; | |
| 2021 } while (start < end); | |
| 2022 if (isLast) | |
| 2023 this.close(); | |
| 2024 } | |
| 2025 } | |
| 2026 class Utf8Decoder extends Converter$(core.List$(core.int), core.String) { | |
| 2027 Utf8Decoder(opt$) { | |
| 2028 let allowMalformed = opt$.allowMalformed === void 0 ? false : opt$.allowMa
lformed; | |
| 2029 this._allowMalformed = allowMalformed; | |
| 2030 super.Converter(); | |
| 2031 } | |
| 2032 convert(codeUnits, start, end) { | |
| 2033 if (start === void 0) | |
| 2034 start = 0; | |
| 2035 if (end === void 0) | |
| 2036 end = null; | |
| 2037 let length = codeUnits.length; | |
| 2038 core.RangeError.checkValidRange(start, end, length); | |
| 2039 if (end === null) | |
| 2040 end = length; | |
| 2041 let buffer = new core.StringBuffer(); | |
| 2042 let decoder = new _Utf8Decoder(buffer, this._allowMalformed); | |
| 2043 decoder.convert(codeUnits, start, end); | |
| 2044 decoder.close(); | |
| 2045 return buffer.toString(); | |
| 2046 } | |
| 2047 startChunkedConversion(sink) { | |
| 2048 let stringSink = null; | |
| 2049 if (dart.is(sink, StringConversionSink)) { | |
| 2050 stringSink = sink; | |
| 2051 } else { | |
| 2052 stringSink = new StringConversionSink.from(sink); | |
| 2053 } | |
| 2054 return stringSink.asUtf8Sink(this._allowMalformed); | |
| 2055 } | |
| 2056 bind(stream) { | |
| 2057 return dart.as(super.bind(stream), async.Stream$(core.String)); | |
| 2058 } | |
| 2059 fuse(next) { | |
| 2060 return super.fuse(next); | |
| 2061 } | |
| 2062 } | |
| 2063 let _ONE_BYTE_LIMIT = 127; | |
| 2064 let _TWO_BYTE_LIMIT = 2047; | |
| 2065 let _THREE_BYTE_LIMIT = 65535; | |
| 2066 let _FOUR_BYTE_LIMIT = 1114111; | |
| 2067 let _SURROGATE_MASK = 63488; | |
| 2068 let _SURROGATE_TAG_MASK = 64512; | |
| 2069 let _SURROGATE_VALUE_MASK = 1023; | |
| 2070 let _LEAD_SURROGATE_MIN = 55296; | |
| 2071 let _TAIL_SURROGATE_MIN = 56320; | |
| 2072 // Function _isSurrogate: (int) → bool | |
| 2073 function _isSurrogate(codeUnit) { | |
| 2074 return (codeUnit & _SURROGATE_MASK) === _LEAD_SURROGATE_MIN; | |
| 2075 } | |
| 2076 // Function _isLeadSurrogate: (int) → bool | |
| 2077 function _isLeadSurrogate(codeUnit) { | |
| 2078 return (codeUnit & _SURROGATE_TAG_MASK) === _LEAD_SURROGATE_MIN; | |
| 2079 } | |
| 2080 // Function _isTailSurrogate: (int) → bool | |
| 2081 function _isTailSurrogate(codeUnit) { | |
| 2082 return (codeUnit & _SURROGATE_TAG_MASK) === _TAIL_SURROGATE_MIN; | |
| 2083 } | |
| 2084 // Function _combineSurrogatePair: (int, int) → int | |
| 2085 function _combineSurrogatePair(lead, tail) { | |
| 2086 return 65536 + ((lead & _SURROGATE_VALUE_MASK) << 10) | tail & _SURROGATE_VA
LUE_MASK; | |
| 2087 } | |
| 2088 class _Utf8Decoder extends dart.Object { | |
| 2089 _Utf8Decoder(_stringSink, _allowMalformed) { | |
| 2090 this._stringSink = _stringSink; | |
| 2091 this._allowMalformed = _allowMalformed; | |
| 2092 this._isFirstCharacter = true; | |
| 2093 this._value = 0; | |
| 2094 this._expectedUnits = 0; | |
| 2095 this._extraUnits = 0; | |
| 2096 } | |
| 2097 get hasPartialInput() { | |
| 2098 return this._expectedUnits > 0; | |
| 2099 } | |
| 2100 close() { | |
| 2101 this.flush(); | |
| 2102 } | |
| 2103 flush() { | |
| 2104 if (this.hasPartialInput) { | |
| 2105 if (!dart.notNull(this._allowMalformed)) { | |
| 2106 throw new core.FormatException("Unfinished UTF-8 octet sequence"); | |
| 2107 } | |
| 2108 this._stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE); | |
| 2109 this._value = 0; | |
| 2110 this._expectedUnits = 0; | |
| 2111 this._extraUnits = 0; | |
| 2112 } | |
| 2113 } | |
| 2114 convert(codeUnits, startIndex, endIndex) { | |
| 2115 let value = this._value; | |
| 2116 let expectedUnits = this._expectedUnits; | |
| 2117 let extraUnits = this._extraUnits; | |
| 2118 this._value = 0; | |
| 2119 this._expectedUnits = 0; | |
| 2120 this._extraUnits = 0; | |
| 2121 // Function scanOneByteCharacters: (dynamic, int) → int | |
| 2122 function scanOneByteCharacters(units, from) { | |
| 2123 let to = endIndex; | |
| 2124 let mask = _ONE_BYTE_LIMIT; | |
| 2125 for (let i = from; i < to; i++) { | |
| 2126 let unit = dart.dindex(units, i); | |
| 2127 if (!dart.equals(dart.dbinary(unit, '&', mask), unit)) | |
| 2128 return i - from; | |
| 2129 } | |
| 2130 return to - from; | |
| 2131 } | |
| 2132 // Function addSingleBytes: (int, int) → void | |
| 2133 function addSingleBytes(from, to) { | |
| 2134 dart.assert(dart.notNull(from >= startIndex) && dart.notNull(from <= end
Index)); | |
| 2135 dart.assert(dart.notNull(to >= startIndex) && dart.notNull(to <= endInde
x)); | |
| 2136 this._stringSink.write(new core.String.fromCharCodes(codeUnits, from, to
)); | |
| 2137 } | |
| 2138 let i = startIndex; | |
| 2139 loop: | |
| 2140 while (true) { | |
| 2141 multibyte: | |
| 2142 if (expectedUnits > 0) { | |
| 2143 do { | |
| 2144 if (i === endIndex) { | |
| 2145 break loop; | |
| 2146 } | |
| 2147 let unit = codeUnits.get(i); | |
| 2148 if ((unit & 192) !== 128) { | |
| 2149 expectedUnits = 0; | |
| 2150 if (!dart.notNull(this._allowMalformed)) { | |
| 2151 throw new core.FormatException(`Bad UTF-8 encoding 0x${unit.
toRadixString(16)}`); | |
| 2152 } | |
| 2153 this._isFirstCharacter = false; | |
| 2154 this._stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_R
UNE); | |
| 2155 break multibyte; | |
| 2156 } else { | |
| 2157 value = value << 6 | unit & 63; | |
| 2158 expectedUnits--; | |
| 2159 i++; | |
| 2160 } | |
| 2161 } while (expectedUnits > 0); | |
| 2162 if (value <= _LIMITS.get(extraUnits - 1)) { | |
| 2163 if (!dart.notNull(this._allowMalformed)) { | |
| 2164 throw new core.FormatException(`Overlong encoding of 0x${value
.toRadixString(16)}`); | |
| 2165 } | |
| 2166 expectedUnits = extraUnits = 0; | |
| 2167 value = UNICODE_REPLACEMENT_CHARACTER_RUNE; | |
| 2168 } | |
| 2169 if (value > _FOUR_BYTE_LIMIT) { | |
| 2170 if (!dart.notNull(this._allowMalformed)) { | |
| 2171 throw new core.FormatException("Character outside valid Unicod
e range: " + `0x${value.toRadixString(16)}`); | |
| 2172 } | |
| 2173 value = UNICODE_REPLACEMENT_CHARACTER_RUNE; | |
| 2174 } | |
| 2175 if (dart.notNull(!dart.notNull(this._isFirstCharacter)) || dart.no
tNull(value !== UNICODE_BOM_CHARACTER_RUNE)) { | |
| 2176 this._stringSink.writeCharCode(value); | |
| 2177 } | |
| 2178 this._isFirstCharacter = false; | |
| 2179 } | |
| 2180 while (i < endIndex) { | |
| 2181 let oneBytes = scanOneByteCharacters(codeUnits, i); | |
| 2182 if (oneBytes > 0) { | |
| 2183 this._isFirstCharacter = false; | |
| 2184 addSingleBytes(i, i + oneBytes); | |
| 2185 i = oneBytes; | |
| 2186 if (i === endIndex) | |
| 2187 break; | |
| 2188 } | |
| 2189 let unit = codeUnits.get(i++); | |
| 2190 if (unit < 0) { | |
| 2191 if (!dart.notNull(this._allowMalformed)) { | |
| 2192 throw new core.FormatException(`Negative UTF-8 code unit: -0x${(
-unit).toRadixString(16)}`); | |
| 2193 } | |
| 2194 this._stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE)
; | |
| 2195 } else { | |
| 2196 dart.assert(unit > _ONE_BYTE_LIMIT); | |
| 2197 if ((unit & 224) === 192) { | |
| 2198 value = unit & 31; | |
| 2199 expectedUnits = extraUnits = 1; | |
| 2200 continue loop; | |
| 2201 } | |
| 2202 if ((unit & 240) === 224) { | |
| 2203 value = unit & 15; | |
| 2204 expectedUnits = extraUnits = 2; | |
| 2205 continue loop; | |
| 2206 } | |
| 2207 if (dart.notNull((unit & 248) === 240) && dart.notNull(unit < 245)
) { | |
| 2208 value = unit & 7; | |
| 2209 expectedUnits = extraUnits = 3; | |
| 2210 continue loop; | |
| 2211 } | |
| 2212 if (!dart.notNull(this._allowMalformed)) { | |
| 2213 throw new core.FormatException(`Bad UTF-8 encoding 0x${unit.toRa
dixString(16)}`); | |
| 2214 } | |
| 2215 value = UNICODE_REPLACEMENT_CHARACTER_RUNE; | |
| 2216 expectedUnits = extraUnits = 0; | |
| 2217 this._isFirstCharacter = false; | |
| 2218 this._stringSink.writeCharCode(value); | |
| 2219 } | |
| 2220 } | |
| 2221 break loop; | |
| 2222 } | |
| 2223 if (expectedUnits > 0) { | |
| 2224 this._value = value; | |
| 2225 this._expectedUnits = expectedUnits; | |
| 2226 this._extraUnits = extraUnits; | |
| 2227 } | |
| 2228 } | |
| 2229 } | |
| 2230 _Utf8Decoder._LIMITS = /* Unimplemented const */new List.from([_ONE_BYTE_LIMIT
, _TWO_BYTE_LIMIT, _THREE_BYTE_LIMIT, _FOUR_BYTE_LIMIT]); | |
| 2231 // Exports: | |
| 2232 exports.ASCII = ASCII; | |
| 2233 exports.AsciiCodec = AsciiCodec; | |
| 2234 exports.AsciiEncoder = AsciiEncoder; | |
| 2235 exports.AsciiDecoder = AsciiDecoder; | |
| 2236 exports.ByteConversionSink = ByteConversionSink; | |
| 2237 exports.ByteConversionSinkBase = ByteConversionSinkBase; | |
| 2238 exports.ChunkedConversionSink = ChunkedConversionSink; | |
| 2239 exports.ChunkedConversionSink$ = ChunkedConversionSink$; | |
| 2240 exports.Codec = Codec; | |
| 2241 exports.Codec$ = Codec$; | |
| 2242 exports.Converter = Converter; | |
| 2243 exports.Converter$ = Converter$; | |
| 2244 exports.Encoding = Encoding; | |
| 2245 exports.HTML_ESCAPE = HTML_ESCAPE; | |
| 2246 exports.HtmlEscapeMode = HtmlEscapeMode; | |
| 2247 exports.HtmlEscape = HtmlEscape; | |
| 2248 exports.JsonUnsupportedObjectError = JsonUnsupportedObjectError; | |
| 2249 exports.JsonCyclicError = JsonCyclicError; | |
| 2250 exports.JSON = JSON; | |
| 2251 exports.JsonCodec = JsonCodec; | |
| 2252 exports.JsonEncoder = JsonEncoder; | |
| 2253 exports.JsonUtf8Encoder = JsonUtf8Encoder; | |
| 2254 exports.JsonDecoder = JsonDecoder; | |
| 2255 exports.LATIN1 = LATIN1; | |
| 2256 exports.Latin1Codec = Latin1Codec; | |
| 2257 exports.Latin1Encoder = Latin1Encoder; | |
| 2258 exports.Latin1Decoder = Latin1Decoder; | |
| 2259 exports.LineSplitter = LineSplitter; | |
| 2260 exports.StringConversionSink = StringConversionSink; | |
| 2261 exports.ClosableStringSink = ClosableStringSink; | |
| 2262 exports.StringConversionSinkBase = StringConversionSinkBase; | |
| 2263 exports.StringConversionSinkMixin = StringConversionSinkMixin; | |
| 2264 exports.UNICODE_REPLACEMENT_CHARACTER_RUNE = UNICODE_REPLACEMENT_CHARACTER_RUN
E; | |
| 2265 exports.UNICODE_BOM_CHARACTER_RUNE = UNICODE_BOM_CHARACTER_RUNE; | |
| 2266 exports.UTF8 = UTF8; | |
| 2267 exports.Utf8Codec = Utf8Codec; | |
| 2268 exports.Utf8Encoder = Utf8Encoder; | |
| 2269 exports.Utf8Decoder = Utf8Decoder; | |
| 2270 })(convert || (convert = {})); | |
| OLD | NEW |