Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Unified Diff: runtime/lib/string_patch.dart

Issue 15348003: Fix string.trim (adding more runes). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update comment with whitespace property. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/core/string.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string_patch.dart
diff --git a/runtime/lib/string_patch.dart b/runtime/lib/string_patch.dart
index 3fb0f721ee8ba398e5d9b24246fe188ac7b2aa04..dbe8dc03ee2bb269a54219b75282051ae9a74fd6 100644
--- a/runtime/lib/string_patch.dart
+++ b/runtime/lib/string_patch.dart
@@ -200,12 +200,40 @@ class _StringBase {
native "StringBase_substringUnchecked";
// Checks for one-byte whitespaces only.
- // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
- // whitespaces for one byte strings.
static bool _isOneByteWhitespace(int codePoint) {
return
(codePoint == 32) || // Space.
- ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
+ ((9 <= codePoint) && (codePoint <= 13)) || // CR, LF, TAB, etc.
+ (codePoint == 0x85) || // NEL
+ (codePoint == 0xA0); // NBSP
+ }
+
+ // Characters with Whitespace property (Unicode 6.2).
+ // 0009..000D ; White_Space # Cc <control-0009>..<control-000D>
+ // 0020 ; White_Space # Zs SPACE
+ // 0085 ; White_Space # Cc <control-0085>
+ // 00A0 ; White_Space # Zs NO-BREAK SPACE
+ // 1680 ; White_Space # Zs OGHAM SPACE MARK
+ // 180E ; White_Space # Zs MONGOLIAN VOWEL SEPARATOR
+ // 2000..200A ; White_Space # Zs EN QUAD..HAIR SPACE
+ // 2028 ; White_Space # Zl LINE SEPARATOR
+ // 2029 ; White_Space # Zp PARAGRAPH SEPARATOR
+ // 202F ; White_Space # Zs NARROW NO-BREAK SPACE
+ // 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE
+ // 3000 ; White_Space # Zs IDEOGRAPHIC SPACE
+ //
+ // BOM: 0xFEFF
+ static bool _isTwoByteWhitespace(int codePoint) {
+ if (codePoint < 256) return _isOneByteWhitespace(codePoint);
+ return (codePoint == 0x1680) ||
+ (codePoint == 0x180E) ||
+ ((0x2000 <= codePoint) && (codePoint <= 0x200A)) ||
+ (codePoint == 0x2028) ||
+ (codePoint == 0x2029) ||
+ (codePoint == 0x202F) ||
+ (codePoint == 0x205F) ||
+ (codePoint == 0x3000) ||
+ (codePoint == 0xFEFF);
}
String trim() {
@@ -573,8 +601,7 @@ class _TwoByteString extends _StringBase implements String {
}
bool _isWhitespace(int codePoint) {
- // For now we only check for one byte white space characters.
- return _StringBase._isOneByteWhitespace(codePoint);
+ return _StringBase._isTwoByteWhitespace(codePoint);
}
}
@@ -598,8 +625,7 @@ class _ExternalTwoByteString extends _StringBase implements String {
}
bool _isWhitespace(int codePoint) {
- // For now we only check for one byte white space characters.
- return _StringBase._isOneByteWhitespace(codePoint);
+ return _StringBase._isTwoByteWhitespace(codePoint);
}
}
« no previous file with comments | « no previous file | sdk/lib/core/string.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698