| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Provide a list of Unicode codepoints for a given string. | 6 * Provide a list of Unicode codepoints for a given string. |
| 7 */ | 7 */ |
| 8 List<int> stringToCodepoints(String str) { | 8 List<int> stringToCodepoints(String str) { |
| 9 List<int> codepoints; | 9 List<int> codepoints; |
| 10 // TODO _is16BitCodeUnit() is used to work around a bug with frog/dartc | 10 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js |
| 11 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider | 11 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider |
| 12 // removing after this issue is resolved. | 12 // removing after this issue is resolved. |
| 13 if (_is16BitCodeUnit()) { | 13 if (_is16BitCodeUnit()) { |
| 14 codepoints = _utf16CodeUnitsToCodepoints(str.charCodes()); | 14 codepoints = _utf16CodeUnitsToCodepoints(str.charCodes()); |
| 15 } else { | 15 } else { |
| 16 codepoints = str.charCodes(); | 16 codepoints = str.charCodes(); |
| 17 } | 17 } |
| 18 return codepoints; | 18 return codepoints; |
| 19 } | 19 } |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Generate a string from the provided Unicode codepoints. | 22 * Generate a string from the provided Unicode codepoints. |
| 23 */ | 23 */ |
| 24 String codepointsToString(List<int> codepoints) { | 24 String codepointsToString(List<int> codepoints) { |
| 25 // TODO _is16BitCodeUnit() is used to work around a bug with frog/dartc | 25 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js |
| 26 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider | 26 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider |
| 27 // removing after this issue is resolved. | 27 // removing after this issue is resolved. |
| 28 if (_is16BitCodeUnit()) { | 28 if (_is16BitCodeUnit()) { |
| 29 return new String.fromCharCodes( | 29 return new String.fromCharCodes( |
| 30 _codepointsToUtf16CodeUnits(codepoints)); | 30 _codepointsToUtf16CodeUnits(codepoints)); |
| 31 } else { | 31 } else { |
| 32 return new String.fromCharCodes(codepoints); | 32 return new String.fromCharCodes(codepoints); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 /* | 36 /* |
| 37 * Test for presence of bug related to the use of UTF-16 code units for | 37 * Test for presence of bug related to the use of UTF-16 code units for |
| 38 * Dart compiled to JS. | 38 * Dart compiled to JS. |
| 39 */ | 39 */ |
| 40 bool _test16BitCodeUnit = null; | 40 bool _test16BitCodeUnit = null; |
| 41 // TODO _is16BitCodeUnit() is used to work around a bug with frog/dartc | 41 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js |
| 42 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider | 42 // (http://code.google.com/p/dart/issues/detail?id=1357). Consider |
| 43 // removing after this issue is resolved. | 43 // removing after this issue is resolved. |
| 44 bool _is16BitCodeUnit() { | 44 bool _is16BitCodeUnit() { |
| 45 if (_test16BitCodeUnit == null) { | 45 if (_test16BitCodeUnit == null) { |
| 46 _test16BitCodeUnit = (new String.fromCharCodes([0x1D11E])) == | 46 _test16BitCodeUnit = (new String.fromCharCodes([0x1D11E])) == |
| 47 (new String.fromCharCodes([0xD11E])); | 47 (new String.fromCharCodes([0xD11E])); |
| 48 } | 48 } |
| 49 return _test16BitCodeUnit; | 49 return _test16BitCodeUnit; |
| 50 } | 50 } |
| 51 | 51 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 _offset -= by; | 266 _offset -= by; |
| 267 } | 267 } |
| 268 | 268 |
| 269 int get remaining() => _end - _offset; | 269 int get remaining() => _end - _offset; |
| 270 | 270 |
| 271 void skip([int count = 1]) { | 271 void skip([int count = 1]) { |
| 272 _offset += count; | 272 _offset += count; |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| OLD | NEW |