OLD | NEW |
1 dart_library.library('dart/convert', null, /* Imports */[ | 1 dart_library.library('dart/convert', null, /* Imports */[ |
2 'dart/_runtime', | 2 'dart/_runtime', |
3 'dart/core', | 3 'dart/core', |
4 'dart/async', | 4 'dart/async', |
5 'dart/typed_data', | 5 'dart/typed_data', |
6 'dart/_internal', | 6 'dart/_internal', |
7 'dart/collection' | 7 'dart/collection' |
8 ], /* Lazy imports */[ | 8 ], /* Lazy imports */[ |
9 ], function(exports, dart, core, async, typed_data, _internal, collection) { | 9 ], function(exports, dart, core, async, typed_data, _internal, collection) { |
10 'use strict'; | 10 'use strict'; |
11 let dartx = dart.dartx; | 11 let dartx = dart.dartx; |
| 12 const _allowInvalid = Symbol('_allowInvalid'); |
12 const Codec$ = dart.generic(function(S, T) { | 13 const Codec$ = dart.generic(function(S, T) { |
13 class Codec extends core.Object { | 14 class Codec extends core.Object { |
14 Codec() { | 15 Codec() { |
15 } | 16 } |
16 encode(input) { | 17 encode(input) { |
17 dart.as(input, S); | 18 dart.as(input, S); |
18 return this.encoder.convert(input); | 19 return this.encoder.convert(input); |
19 } | 20 } |
20 decode(encoded) { | 21 decode(encoded) { |
21 dart.as(encoded, T); | 22 dart.as(encoded, T); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 methods: () => ({decodeStream: [async.Future$(core.String), [async.Stream$(c
ore.List$(core.int))]]}), | 62 methods: () => ({decodeStream: [async.Future$(core.String), [async.Stream$(c
ore.List$(core.int))]]}), |
62 statics: () => ({getByName: [Encoding, [core.String]]}), | 63 statics: () => ({getByName: [Encoding, [core.String]]}), |
63 names: ['getByName'] | 64 names: ['getByName'] |
64 }); | 65 }); |
65 dart.defineLazyProperties(Encoding, { | 66 dart.defineLazyProperties(Encoding, { |
66 get _nameToEncoding() { | 67 get _nameToEncoding() { |
67 return dart.map({"iso_8859-1:1987": LATIN1, "iso-ir-100": LATIN1, "iso_885
9-1": LATIN1, "iso-8859-1": LATIN1, latin1: LATIN1, l1: LATIN1, ibm819: LATIN1,
cp819: LATIN1, csisolatin1: LATIN1, "iso-ir-6": ASCII, "ansi_x3.4-1968": ASCII,
"ansi_x3.4-1986": ASCII, "iso_646.irv:1991": ASCII, "iso646-us": ASCII, "us-asci
i": ASCII, us: ASCII, ibm367: ASCII, cp367: ASCII, csascii: ASCII, ascii: ASCII,
csutf8: UTF8, "utf-8": UTF8}, core.String, Encoding); | 68 return dart.map({"iso_8859-1:1987": LATIN1, "iso-ir-100": LATIN1, "iso_885
9-1": LATIN1, "iso-8859-1": LATIN1, latin1: LATIN1, l1: LATIN1, ibm819: LATIN1,
cp819: LATIN1, csisolatin1: LATIN1, "iso-ir-6": ASCII, "ansi_x3.4-1968": ASCII,
"ansi_x3.4-1986": ASCII, "iso_646.irv:1991": ASCII, "iso646-us": ASCII, "us-asci
i": ASCII, us: ASCII, ibm367: ASCII, cp367: ASCII, csascii: ASCII, ascii: ASCII,
csutf8: UTF8, "utf-8": UTF8}, core.String, Encoding); |
68 }, | 69 }, |
69 set _nameToEncoding(_) {} | 70 set _nameToEncoding(_) {} |
70 }); | 71 }); |
71 const _allowInvalid = Symbol('_allowInvalid'); | |
72 class AsciiCodec extends Encoding { | 72 class AsciiCodec extends Encoding { |
73 AsciiCodec(opts) { | 73 AsciiCodec(opts) { |
74 let allowInvalid = opts && 'allowInvalid' in opts ? opts.allowInvalid : fa
lse; | 74 let allowInvalid = opts && 'allowInvalid' in opts ? opts.allowInvalid : fa
lse; |
75 this[_allowInvalid] = allowInvalid; | 75 this[_allowInvalid] = allowInvalid; |
76 super.Encoding(); | 76 super.Encoding(); |
77 } | 77 } |
78 get name() { | 78 get name() { |
79 return "us-ascii"; | 79 return "us-ascii"; |
80 } | 80 } |
81 decode(bytes, opts) { | 81 decode(bytes, opts) { |
(...skipping 11 matching lines...) Expand all Loading... |
93 get decoder() { | 93 get decoder() { |
94 return dart.notNull(this[_allowInvalid]) ? dart.const(new AsciiDecoder({al
lowInvalid: true})) : dart.const(new AsciiDecoder({allowInvalid: false})); | 94 return dart.notNull(this[_allowInvalid]) ? dart.const(new AsciiDecoder({al
lowInvalid: true})) : dart.const(new AsciiDecoder({allowInvalid: false})); |
95 } | 95 } |
96 } | 96 } |
97 dart.setSignature(AsciiCodec, { | 97 dart.setSignature(AsciiCodec, { |
98 constructors: () => ({AsciiCodec: [AsciiCodec, [], {allowInvalid: core.bool}
]}), | 98 constructors: () => ({AsciiCodec: [AsciiCodec, [], {allowInvalid: core.bool}
]}), |
99 methods: () => ({decode: [core.String, [core.List$(core.int)], {allowInvalid
: core.bool}]}) | 99 methods: () => ({decode: [core.String, [core.List$(core.int)], {allowInvalid
: core.bool}]}) |
100 }); | 100 }); |
101 const ASCII = dart.const(new AsciiCodec()); | 101 const ASCII = dart.const(new AsciiCodec()); |
102 const _ASCII_MASK = 127; | 102 const _ASCII_MASK = 127; |
| 103 const _subsetMask = Symbol('_subsetMask'); |
103 const Converter$ = dart.generic(function(S, T) { | 104 const Converter$ = dart.generic(function(S, T) { |
104 class Converter extends core.Object { | 105 class Converter extends core.Object { |
105 Converter() { | 106 Converter() { |
106 } | 107 } |
107 fuse(other) { | 108 fuse(other) { |
108 dart.as(other, Converter$(T, dart.dynamic)); | 109 dart.as(other, Converter$(T, dart.dynamic)); |
109 return new (_FusedConverter$(S, T, dart.dynamic))(this, other); | 110 return new (_FusedConverter$(S, T, dart.dynamic))(this, other); |
110 } | 111 } |
111 startChunkedConversion(sink) { | 112 startChunkedConversion(sink) { |
112 dart.as(sink, core.Sink$(T)); | 113 dart.as(sink, core.Sink$(T)); |
113 dart.throw(new core.UnsupportedError(`This converter does not support ch
unked conversions: ${this}`)); | 114 dart.throw(new core.UnsupportedError(`This converter does not support ch
unked conversions: ${this}`)); |
114 } | 115 } |
115 bind(source) { | 116 bind(source) { |
116 dart.as(source, async.Stream$(S)); | 117 dart.as(source, async.Stream$(S)); |
117 return async.Stream$(T).eventTransformed(source, dart.fn(sink => new _Co
nverterStreamEventSink(this, sink), _ConverterStreamEventSink, [async.EventSink]
)); | 118 return async.Stream$(T).eventTransformed(source, dart.fn(sink => new _Co
nverterStreamEventSink(this, sink), _ConverterStreamEventSink, [async.EventSink]
)); |
118 } | 119 } |
119 } | 120 } |
120 Converter[dart.implements] = () => [async.StreamTransformer$(S, T)]; | 121 Converter[dart.implements] = () => [async.StreamTransformer$(S, T)]; |
121 dart.setSignature(Converter, { | 122 dart.setSignature(Converter, { |
122 constructors: () => ({Converter: [Converter$(S, T), []]}), | 123 constructors: () => ({Converter: [Converter$(S, T), []]}), |
123 methods: () => ({ | 124 methods: () => ({ |
124 fuse: [Converter$(S, dart.dynamic), [Converter$(T, dart.dynamic)]], | 125 fuse: [Converter$(S, dart.dynamic), [Converter$(T, dart.dynamic)]], |
125 startChunkedConversion: [ChunkedConversionSink, [core.Sink$(T)]], | 126 startChunkedConversion: [ChunkedConversionSink, [core.Sink$(T)]], |
126 bind: [async.Stream$(T), [async.Stream$(S)]] | 127 bind: [async.Stream$(T), [async.Stream$(S)]] |
127 }) | 128 }) |
128 }); | 129 }); |
129 return Converter; | 130 return Converter; |
130 }); | 131 }); |
131 let Converter = Converter$(); | 132 let Converter = Converter$(); |
132 const _subsetMask = Symbol('_subsetMask'); | |
133 class _UnicodeSubsetEncoder extends Converter$(core.String, core.List$(core.in
t)) { | 133 class _UnicodeSubsetEncoder extends Converter$(core.String, core.List$(core.in
t)) { |
134 _UnicodeSubsetEncoder(subsetMask) { | 134 _UnicodeSubsetEncoder(subsetMask) { |
135 this[_subsetMask] = subsetMask; | 135 this[_subsetMask] = subsetMask; |
136 super.Converter(); | 136 super.Converter(); |
137 } | 137 } |
138 convert(string, start, end) { | 138 convert(string, start, end) { |
139 if (start === void 0) start = 0; | 139 if (start === void 0) start = 0; |
140 if (end === void 0) end = null; | 140 if (end === void 0) end = null; |
141 let stringLength = string[dartx.length]; | 141 let stringLength = string[dartx.length]; |
142 core.RangeError.checkValidRange(start, end, stringLength); | 142 core.RangeError.checkValidRange(start, end, stringLength); |
(...skipping 28 matching lines...) Expand all Loading... |
171 }) | 171 }) |
172 }); | 172 }); |
173 class AsciiEncoder extends _UnicodeSubsetEncoder { | 173 class AsciiEncoder extends _UnicodeSubsetEncoder { |
174 AsciiEncoder() { | 174 AsciiEncoder() { |
175 super._UnicodeSubsetEncoder(_ASCII_MASK); | 175 super._UnicodeSubsetEncoder(_ASCII_MASK); |
176 } | 176 } |
177 } | 177 } |
178 dart.setSignature(AsciiEncoder, { | 178 dart.setSignature(AsciiEncoder, { |
179 constructors: () => ({AsciiEncoder: [AsciiEncoder, []]}) | 179 constructors: () => ({AsciiEncoder: [AsciiEncoder, []]}) |
180 }); | 180 }); |
| 181 const _sink = Symbol('_sink'); |
181 class StringConversionSinkMixin extends core.Object { | 182 class StringConversionSinkMixin extends core.Object { |
182 add(str) { | 183 add(str) { |
183 return this.addSlice(str, 0, str[dartx.length], false); | 184 return this.addSlice(str, 0, str[dartx.length], false); |
184 } | 185 } |
185 asUtf8Sink(allowMalformed) { | 186 asUtf8Sink(allowMalformed) { |
186 return new _Utf8ConversionSink(this, allowMalformed); | 187 return new _Utf8ConversionSink(this, allowMalformed); |
187 } | 188 } |
188 asStringSink() { | 189 asStringSink() { |
189 return new _StringConversionSinkAsStringSinkAdapter(this); | 190 return new _StringConversionSinkAsStringSinkAdapter(this); |
190 } | 191 } |
191 } | 192 } |
192 StringConversionSinkMixin[dart.implements] = () => [StringConversionSink]; | 193 StringConversionSinkMixin[dart.implements] = () => [StringConversionSink]; |
193 dart.setSignature(StringConversionSinkMixin, { | 194 dart.setSignature(StringConversionSinkMixin, { |
194 methods: () => ({ | 195 methods: () => ({ |
195 add: [dart.void, [core.String]], | 196 add: [dart.void, [core.String]], |
196 asUtf8Sink: [ByteConversionSink, [core.bool]], | 197 asUtf8Sink: [ByteConversionSink, [core.bool]], |
197 asStringSink: [ClosableStringSink, []] | 198 asStringSink: [ClosableStringSink, []] |
198 }) | 199 }) |
199 }); | 200 }); |
200 class StringConversionSinkBase extends StringConversionSinkMixin {} | 201 class StringConversionSinkBase extends StringConversionSinkMixin {} |
201 const _sink = Symbol('_sink'); | |
202 class _UnicodeSubsetEncoderSink extends StringConversionSinkBase { | 202 class _UnicodeSubsetEncoderSink extends StringConversionSinkBase { |
203 _UnicodeSubsetEncoderSink(subsetMask, sink) { | 203 _UnicodeSubsetEncoderSink(subsetMask, sink) { |
204 this[_subsetMask] = subsetMask; | 204 this[_subsetMask] = subsetMask; |
205 this[_sink] = sink; | 205 this[_sink] = sink; |
206 } | 206 } |
207 close() { | 207 close() { |
208 this[_sink].close(); | 208 this[_sink].close(); |
209 } | 209 } |
210 addSlice(source, start, end, isLast) { | 210 addSlice(source, start, end, isLast) { |
211 core.RangeError.checkValidRange(start, end, source[dartx.length]); | 211 core.RangeError.checkValidRange(start, end, source[dartx.length]); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 return new _ErrorHandlingAsciiDecoderSink(stringSink.asUtf8Sink(false)); | 290 return new _ErrorHandlingAsciiDecoderSink(stringSink.asUtf8Sink(false)); |
291 } else { | 291 } else { |
292 return new _SimpleAsciiDecoderSink(stringSink); | 292 return new _SimpleAsciiDecoderSink(stringSink); |
293 } | 293 } |
294 } | 294 } |
295 } | 295 } |
296 dart.setSignature(AsciiDecoder, { | 296 dart.setSignature(AsciiDecoder, { |
297 constructors: () => ({AsciiDecoder: [AsciiDecoder, [], {allowInvalid: core.b
ool}]}), | 297 constructors: () => ({AsciiDecoder: [AsciiDecoder, [], {allowInvalid: core.b
ool}]}), |
298 methods: () => ({startChunkedConversion: [ByteConversionSink, [core.Sink$(co
re.String)]]}) | 298 methods: () => ({startChunkedConversion: [ByteConversionSink, [core.Sink$(co
re.String)]]}) |
299 }); | 299 }); |
| 300 const _utf8Sink = Symbol('_utf8Sink'); |
300 const ChunkedConversionSink$ = dart.generic(function(T) { | 301 const ChunkedConversionSink$ = dart.generic(function(T) { |
301 class ChunkedConversionSink extends core.Object { | 302 class ChunkedConversionSink extends core.Object { |
302 ChunkedConversionSink() { | 303 ChunkedConversionSink() { |
303 } | 304 } |
304 static withCallback(callback) { | 305 static withCallback(callback) { |
305 return new (_SimpleCallbackSink$(T))(callback); | 306 return new (_SimpleCallbackSink$(T))(callback); |
306 } | 307 } |
307 } | 308 } |
308 ChunkedConversionSink[dart.implements] = () => [core.Sink$(T)]; | 309 ChunkedConversionSink[dart.implements] = () => [core.Sink$(T)]; |
309 dart.setSignature(ChunkedConversionSink, { | 310 dart.setSignature(ChunkedConversionSink, { |
(...skipping 28 matching lines...) Expand all Loading... |
338 super.ByteConversionSink(); | 339 super.ByteConversionSink(); |
339 } | 340 } |
340 addSlice(chunk, start, end, isLast) { | 341 addSlice(chunk, start, end, isLast) { |
341 this.add(chunk[dartx.sublist](start, end)); | 342 this.add(chunk[dartx.sublist](start, end)); |
342 if (dart.notNull(isLast)) this.close(); | 343 if (dart.notNull(isLast)) this.close(); |
343 } | 344 } |
344 } | 345 } |
345 dart.setSignature(ByteConversionSinkBase, { | 346 dart.setSignature(ByteConversionSinkBase, { |
346 methods: () => ({addSlice: [dart.void, [core.List$(core.int), core.int, core
.int, core.bool]]}) | 347 methods: () => ({addSlice: [dart.void, [core.List$(core.int), core.int, core
.int, core.bool]]}) |
347 }); | 348 }); |
348 const _utf8Sink = Symbol('_utf8Sink'); | |
349 class _ErrorHandlingAsciiDecoderSink extends ByteConversionSinkBase { | 349 class _ErrorHandlingAsciiDecoderSink extends ByteConversionSinkBase { |
350 _ErrorHandlingAsciiDecoderSink(utf8Sink) { | 350 _ErrorHandlingAsciiDecoderSink(utf8Sink) { |
351 this[_utf8Sink] = utf8Sink; | 351 this[_utf8Sink] = utf8Sink; |
352 } | 352 } |
353 close() { | 353 close() { |
354 this[_utf8Sink].close(); | 354 this[_utf8Sink].close(); |
355 } | 355 } |
356 add(source) { | 356 add(source) { |
357 this.addSlice(source, 0, source[dartx.length], false); | 357 this.addSlice(source, 0, source[dartx.length], false); |
358 } | 358 } |
(...skipping 2469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2828 exports.LineSplitter = LineSplitter; | 2828 exports.LineSplitter = LineSplitter; |
2829 exports.StringConversionSink = StringConversionSink; | 2829 exports.StringConversionSink = StringConversionSink; |
2830 exports.ClosableStringSink = ClosableStringSink; | 2830 exports.ClosableStringSink = ClosableStringSink; |
2831 exports.UNICODE_REPLACEMENT_CHARACTER_RUNE = UNICODE_REPLACEMENT_CHARACTER_RUN
E; | 2831 exports.UNICODE_REPLACEMENT_CHARACTER_RUNE = UNICODE_REPLACEMENT_CHARACTER_RUN
E; |
2832 exports.UNICODE_BOM_CHARACTER_RUNE = UNICODE_BOM_CHARACTER_RUNE; | 2832 exports.UNICODE_BOM_CHARACTER_RUNE = UNICODE_BOM_CHARACTER_RUNE; |
2833 exports.Utf8Codec = Utf8Codec; | 2833 exports.Utf8Codec = Utf8Codec; |
2834 exports.UTF8 = UTF8; | 2834 exports.UTF8 = UTF8; |
2835 exports.Utf8Encoder = Utf8Encoder; | 2835 exports.Utf8Encoder = Utf8Encoder; |
2836 exports.Utf8Decoder = Utf8Decoder; | 2836 exports.Utf8Decoder = Utf8Decoder; |
2837 }); | 2837 }); |
OLD | NEW |