Chromium Code Reviews| Index: runtime/vm/unicode.h |
| diff --git a/runtime/vm/unicode.h b/runtime/vm/unicode.h |
| index 19119bbf579cf9a4e37a17099e25ca4404a3a59f..2dd99339a8667d9122c8b3ef7160bd8624370edb 100644 |
| --- a/runtime/vm/unicode.h |
| +++ b/runtime/vm/unicode.h |
| @@ -33,6 +33,58 @@ class Utf8 : AllStatic { |
| static bool Decode(const char* src, uint32_t* dst, intptr_t len); |
| }; |
| + |
| +class CaseMapping : AllStatic { |
| + public: |
| + // Maps a code point to uppercase. |
| + static int32_t ToUpper(int32_t code_point) { |
| + return Convert(code_point, kUppercase); |
| + } |
| + |
| + // Maps a code point to lowercase. |
| + static int32_t ToLower(int32_t code_point) { |
| + return Convert(code_point, kLowercase); |
| + } |
| + |
| + private: |
| + // Property is a delta to the uppercase mapping. |
| + static const int32_t kUppercase = 1; |
| + |
| + // Property is a delta to the uppercase mapping. |
| + static const int32_t kLowercase = 2; |
| + |
| + // Property is an index into the exception table. |
| + static const int32_t kException = 3; |
| + |
| + // Type bit-field parameters |
| + static const int32_t kTypeShift = 2; |
| + static const int32_t kTypeMask = 3; |
| + |
| + // The size of a stage 2 block in bytes. |
| + static const size_t kBlockSize = 1<<8; |
|
Ivan Posva
2011/10/18 22:01:13
Please name the constant 8, then you can use it be
cshapiro
2011/10/20 02:35:05
Done.
|
| + |
| + static int32_t Convert(int32_t ch, int32_t mapping) { |
| + int16_t offset = stage1_[ch / kBlockSize] * kBlockSize; |
|
Ivan Posva
2011/10/18 22:01:13
Replace the division with a shift with a constant
cshapiro
2011/10/20 02:35:05
Done.
|
| + int32_t info = stage2_[offset + (ch % kBlockSize)]; |
|
Ivan Posva
2011/10/18 22:01:13
Modulo -> and?
cshapiro
2011/10/20 02:35:05
Done.
|
| + int32_t type = info & kTypeMask; |
| + if (type == mapping) { |
| + ch += (info >> kTypeShift); |
| + } else if (type == kException) { |
| + ch += stage2_exception_[info >> kTypeShift][mapping - 1]; |
| + } |
| + return ch; |
| + } |
| + |
| + // Index into the data array. |
| + static const uint8_t stage1_[]; |
| + |
| + // Data for small code points with one mapping |
| + static const int16_t stage2_[]; |
| + |
| + // Data for large code points or code points with both mappings. |
| + static const int32_t stage2_exception_[][2]; |
| +}; |
| + |
| } // namespace dart |
| #endif // VM_UNICODE_H_ |