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 patch class String { | 5 patch class String { |
6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { | 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { |
7 return _StringBase.createFromCharCodes(charCodes); | 7 return _StringBase.createFromCharCodes(charCodes); |
8 } | 8 } |
9 | 9 |
10 /* patch */ factory String.fromCharCode(int charCode) { | 10 /* patch */ factory String.fromCharCode(int charCode) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 if ((startIndex + 1) == endIndex) { | 253 if ((startIndex + 1) == endIndex) { |
254 return this[startIndex]; | 254 return this[startIndex]; |
255 } | 255 } |
256 return _substringUncheckedNative(startIndex, endIndex); | 256 return _substringUncheckedNative(startIndex, endIndex); |
257 } | 257 } |
258 | 258 |
259 String _substringUncheckedNative(int startIndex, int endIndex) | 259 String _substringUncheckedNative(int startIndex, int endIndex) |
260 native "StringBase_substringUnchecked"; | 260 native "StringBase_substringUnchecked"; |
261 | 261 |
262 // Checks for one-byte whitespaces only. | 262 // Checks for one-byte whitespaces only. |
263 static bool _isOneByteWhitespace(int codePoint) { | 263 static bool _isOneByteWhitespace(int codeUnit) { |
264 return | 264 if (codeUnit <= 32) { |
265 (codePoint == 32) || // Space. | 265 return ((codeUnit == 32) || // Space. |
266 ((codePoint <= 13) ? (9 <= codePoint) // CR, LF, TAB, etc. | 266 ((codeUnit <= 13) && (codeUnit >= 9))); // CR, LF, TAB, etc. |
267 : ((codePoint == 0x85) || // NEL | 267 } |
268 (codePoint == 0xA0))); // NBSP | 268 if (codeUnit < 0x85) return false; |
srdjan
2014/09/24 20:05:35
Is that check worth it? With two below you have th
Lasse Reichstein Nielsen
2014/09/24 20:26:30
Ack, probably not for the one-byte case. I copied
Lasse Reichstein Nielsen
2014/09/25 14:37:16
Fixed.
Any chance of optimizing so that (codeunit
| |
269 return (codeUnit == 0x85) || (codeUnit == 0xA0); | |
269 } | 270 } |
270 | 271 |
271 // Characters with Whitespace property (Unicode 6.2). | 272 // Characters with Whitespace property (Unicode 6.2). |
272 // 0009..000D ; White_Space # Cc <control-0009>..<control-000D> | 273 // 0009..000D ; White_Space # Cc <control-0009>..<control-000D> |
273 // 0020 ; White_Space # Zs SPACE | 274 // 0020 ; White_Space # Zs SPACE |
274 // 0085 ; White_Space # Cc <control-0085> | 275 // 0085 ; White_Space # Cc <control-0085> |
275 // 00A0 ; White_Space # Zs NO-BREAK SPACE | 276 // 00A0 ; White_Space # Zs NO-BREAK SPACE |
276 // 1680 ; White_Space # Zs OGHAM SPACE MARK | 277 // 1680 ; White_Space # Zs OGHAM SPACE MARK |
277 // 180E ; White_Space # Zs MONGOLIAN VOWEL SEPARATOR | 278 // 180E ; White_Space # Zs MONGOLIAN VOWEL SEPARATOR |
278 // 2000..200A ; White_Space # Zs EN QUAD..HAIR SPACE | 279 // 2000..200A ; White_Space # Zs EN QUAD..HAIR SPACE |
279 // 2028 ; White_Space # Zl LINE SEPARATOR | 280 // 2028 ; White_Space # Zl LINE SEPARATOR |
280 // 2029 ; White_Space # Zp PARAGRAPH SEPARATOR | 281 // 2029 ; White_Space # Zp PARAGRAPH SEPARATOR |
281 // 202F ; White_Space # Zs NARROW NO-BREAK SPACE | 282 // 202F ; White_Space # Zs NARROW NO-BREAK SPACE |
282 // 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE | 283 // 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE |
283 // 3000 ; White_Space # Zs IDEOGRAPHIC SPACE | 284 // 3000 ; White_Space # Zs IDEOGRAPHIC SPACE |
284 // | 285 // |
285 // BOM: 0xFEFF | 286 // BOM: 0xFEFF |
286 static bool _isTwoByteWhitespace(int codeUnit) { | 287 static bool _isTwoByteWhitespace(int codeUnit) { |
287 if (codeUnit <= 0xA0) return _isOneByteWhitespace(codeUnit); | 288 if (codeUnit <= 32) { |
289 return (codeUnit == 32) || | |
290 ((codeUnit <= 13) && (codeUnit >= 9)); | |
291 } | |
292 if (codeUnit < 0x85) return false; | |
293 if ((codeUnit == 0x85) || (codeUnit == 0xA0)) return true; | |
288 return (codeUnit <= 0x200A) | 294 return (codeUnit <= 0x200A) |
289 ? ((codeUnit == 0x1680) || | 295 ? ((codeUnit == 0x1680) || |
290 (codeUnit == 0x180E) || | 296 (codeUnit == 0x180E) || |
291 (0x2000 <= codeUnit)) | 297 (0x2000 <= codeUnit)) |
292 : ((codeUnit == 0x2028) || | 298 : ((codeUnit == 0x2028) || |
293 (codeUnit == 0x2029) || | 299 (codeUnit == 0x2029) || |
294 (codeUnit == 0x202F) || | 300 (codeUnit == 0x202F) || |
295 (codeUnit == 0x205F) || | 301 (codeUnit == 0x205F) || |
296 (codeUnit == 0x3000) || | 302 (codeUnit == 0x3000) || |
297 (codeUnit == 0xFEFF)); | 303 (codeUnit == 0xFEFF)); |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1018 class _CodeUnits extends Object with ListMixin<int>, | 1024 class _CodeUnits extends Object with ListMixin<int>, |
1019 UnmodifiableListMixin<int> { | 1025 UnmodifiableListMixin<int> { |
1020 /** The string that this is the code units of. */ | 1026 /** The string that this is the code units of. */ |
1021 String _string; | 1027 String _string; |
1022 | 1028 |
1023 _CodeUnits(this._string); | 1029 _CodeUnits(this._string); |
1024 | 1030 |
1025 int get length => _string.length; | 1031 int get length => _string.length; |
1026 int operator[](int i) => _string.codeUnitAt(i); | 1032 int operator[](int i) => _string.codeUnitAt(i); |
1027 } | 1033 } |
OLD | NEW |