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

Unified Diff: runtime/vm/unicode.h

Issue 11416054: Provide a code point iterator to the String class to simplify iteration. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments Created 8 years, 1 month 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
Index: runtime/vm/unicode.h
diff --git a/runtime/vm/unicode.h b/runtime/vm/unicode.h
index 28beaad51592d6233b4db817b145260d57acdccb..bbd34bd158dedfbc4380056a2ffafa4d6431f819 100644
--- a/runtime/vm/unicode.h
+++ b/runtime/vm/unicode.h
@@ -24,11 +24,7 @@ class Utf8 : AllStatic {
static const intptr_t kMaxTwoByteChar = 0x7FF;
static const intptr_t kMaxThreeByteChar = 0xFFFF;
static const intptr_t kMaxFourByteChar = 0x10FFFF;
- static const intptr_t kMaxBmpCodepoint = 0xffff;
- static const int32_t kLeadOffset = (0xD800 - (0x10000 >> 10));
- static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00);
- static void ConvertUTF32ToUTF16(int32_t codepoint, uint16_t* dst);
static intptr_t CodePointCount(const uint8_t* utf8_array,
intptr_t array_len,
Type* type);
@@ -69,6 +65,39 @@ class Utf8 : AllStatic {
};
+class Utf16 : AllStatic {
+ public:
+ static const int32_t kMaxBmpCodepoint = 0xFFFF;
+
+ static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10));
+
+ static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00);
+
+ // Returns true if ch is a lead or trail surrogate.
+ static bool IsSurrogate(int32_t ch) {
+ return (ch & 0xFFFFF800) == 0xD800;
+ }
+
+ // Returns true if ch is a lead surrogate.
+ static bool IsLeadSurrogate(int32_t ch) {
+ return (ch & 0xFFFFFC00) == 0xD800;
+ }
+
+ // Returns true if ch is a low surrogate.
+ static bool IsTrailSurrogate(int32_t ch) {
+ return (ch & 0xFFFFFC00) == 0xDC00;
+ }
+
+ // Decodes a surrogate pair into a supplementary code point.
+ static int32_t Decode(int32_t lead, int32_t trail) {
+ return 0x10000 + ((lead & 0x3FF) << 10) + (trail & 0x3FF);
+ }
+
+ // Encodes a single code point.
+ static void Encode(int32_t codepoint, uint16_t* dst);
+};
+
+
class CaseMapping : AllStatic {
public:
// Maps a code point to uppercase.
« runtime/vm/object.cc ('K') | « runtime/vm/object_test.cc ('k') | runtime/vm/unicode.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698