Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #ifndef VM_UNICODE_H_ | 5 #ifndef VM_UNICODE_H_ |
| 6 #define VM_UNICODE_H_ | 6 #define VM_UNICODE_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 static void Encode(int32_t ch, char* dst); | 27 static void Encode(int32_t ch, char* dst); |
| 28 static intptr_t Encode(const String& src, char* dst, intptr_t len); | 28 static intptr_t Encode(const String& src, char* dst, intptr_t len); |
| 29 | 29 |
| 30 static intptr_t Decode(const char*, int32_t* ch); | 30 static intptr_t Decode(const char*, int32_t* ch); |
| 31 static bool Decode(const char* src, uint8_t* dst, intptr_t len); | 31 static bool Decode(const char* src, uint8_t* dst, intptr_t len); |
| 32 static bool Decode(const char* src, uint16_t* dst, intptr_t len); | 32 static bool Decode(const char* src, uint16_t* dst, intptr_t len); |
| 33 static bool Decode(const char* src, uint32_t* dst, intptr_t len); | 33 static bool Decode(const char* src, uint32_t* dst, intptr_t len); |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 | |
| 37 class CaseMapping : AllStatic { | |
| 38 public: | |
| 39 // Maps a code point to uppercase. | |
| 40 static int32_t ToUpper(int32_t code_point) { | |
| 41 return Convert(code_point, kUppercase); | |
| 42 } | |
| 43 | |
| 44 // Maps a code point to lowercase. | |
| 45 static int32_t ToLower(int32_t code_point) { | |
| 46 return Convert(code_point, kLowercase); | |
| 47 } | |
| 48 | |
| 49 private: | |
| 50 // Property is a delta to the uppercase mapping. | |
| 51 static const int32_t kUppercase = 1; | |
| 52 | |
| 53 // Property is a delta to the uppercase mapping. | |
| 54 static const int32_t kLowercase = 2; | |
| 55 | |
| 56 // Property is an index into the exception table. | |
| 57 static const int32_t kException = 3; | |
| 58 | |
| 59 // Type bit-field parameters | |
| 60 static const int32_t kTypeShift = 2; | |
| 61 static const int32_t kTypeMask = 3; | |
| 62 | |
| 63 // The size of a stage 2 block in bytes. | |
| 64 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.
| |
| 65 | |
| 66 static int32_t Convert(int32_t ch, int32_t mapping) { | |
| 67 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.
| |
| 68 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.
| |
| 69 int32_t type = info & kTypeMask; | |
| 70 if (type == mapping) { | |
| 71 ch += (info >> kTypeShift); | |
| 72 } else if (type == kException) { | |
| 73 ch += stage2_exception_[info >> kTypeShift][mapping - 1]; | |
| 74 } | |
| 75 return ch; | |
| 76 } | |
| 77 | |
| 78 // Index into the data array. | |
| 79 static const uint8_t stage1_[]; | |
| 80 | |
| 81 // Data for small code points with one mapping | |
| 82 static const int16_t stage2_[]; | |
| 83 | |
| 84 // Data for large code points or code points with both mappings. | |
| 85 static const int32_t stage2_exception_[][2]; | |
| 86 }; | |
| 87 | |
| 36 } // namespace dart | 88 } // namespace dart |
| 37 | 89 |
| 38 #endif // VM_UNICODE_H_ | 90 #endif // VM_UNICODE_H_ |
| OLD | NEW |