| 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 #ifndef RUNTIME_VM_UNICODE_H_ | 5 #ifndef RUNTIME_VM_UNICODE_H_ |
| 6 #define RUNTIME_VM_UNICODE_H_ | 6 #define RUNTIME_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 16 matching lines...) Expand all Loading... |
| 27 static bool IsSupplementary(int32_t code_point) { | 27 static bool IsSupplementary(int32_t code_point) { |
| 28 return (code_point > 0xFFFF) && (code_point <= kMaxCodePoint); | 28 return (code_point > 0xFFFF) && (code_point <= kMaxCodePoint); |
| 29 } | 29 } |
| 30 | 30 |
| 31 // Returns true if the code point value is above Plane 17. | 31 // Returns true if the code point value is above Plane 17. |
| 32 static bool IsOutOfRange(intptr_t code_point) { | 32 static bool IsOutOfRange(intptr_t code_point) { |
| 33 return (code_point < 0) || (code_point > kMaxCodePoint); | 33 return (code_point < 0) || (code_point > kMaxCodePoint); |
| 34 } | 34 } |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 | |
| 38 class Utf8 : AllStatic { | 37 class Utf8 : AllStatic { |
| 39 public: | 38 public: |
| 40 enum Type { | 39 enum Type { |
| 41 kLatin1 = 0, // Latin-1 code point [U+0000, U+00FF]. | 40 kLatin1 = 0, // Latin-1 code point [U+0000, U+00FF]. |
| 42 kBMP, // Basic Multilingual Plane code point [U+0000, U+FFFF]. | 41 kBMP, // Basic Multilingual Plane code point [U+0000, U+FFFF]. |
| 43 kSupplementary, // Supplementary code point [U+010000, U+10FFFF]. | 42 kSupplementary, // Supplementary code point [U+010000, U+10FFFF]. |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 // Returns the most restricted coding form in which the sequence of utf8 | 45 // Returns the most restricted coding form in which the sequence of utf8 |
| 47 // characters in 'utf8_array' can be represented in, and the number of | 46 // characters in 'utf8_array' can be represented in, and the number of |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 static bool IsSupplementarySequenceStart(uint8_t code_unit) { | 98 static bool IsSupplementarySequenceStart(uint8_t code_unit) { |
| 100 // Check if utf8 sequence is the start of a codepoint >= U+10000. | 99 // Check if utf8 sequence is the start of a codepoint >= U+10000. |
| 101 return (code_unit >= 0xF0); | 100 return (code_unit >= 0xF0); |
| 102 } | 101 } |
| 103 | 102 |
| 104 static const int8_t kTrailBytes[]; | 103 static const int8_t kTrailBytes[]; |
| 105 static const uint32_t kMagicBits[]; | 104 static const uint32_t kMagicBits[]; |
| 106 static const uint32_t kOverlongMinimum[]; | 105 static const uint32_t kOverlongMinimum[]; |
| 107 }; | 106 }; |
| 108 | 107 |
| 109 | |
| 110 class Utf16 : AllStatic { | 108 class Utf16 : AllStatic { |
| 111 public: | 109 public: |
| 112 // Returns the length of the code point in UTF-16 code units. | 110 // Returns the length of the code point in UTF-16 code units. |
| 113 static intptr_t Length(int32_t ch) { | 111 static intptr_t Length(int32_t ch) { |
| 114 return (ch <= Utf16::kMaxCodeUnit) ? 1 : 2; | 112 return (ch <= Utf16::kMaxCodeUnit) ? 1 : 2; |
| 115 } | 113 } |
| 116 | 114 |
| 117 // Returns true if ch is a lead or trail surrogate. | 115 // Returns true if ch is a lead or trail surrogate. |
| 118 static bool IsSurrogate(uint32_t ch) { return (ch & 0xFFFFF800) == 0xD800; } | 116 static bool IsSurrogate(uint32_t ch) { return (ch & 0xFFFFF800) == 0xD800; } |
| 119 | 117 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 static void Encode(int32_t codepoint, uint16_t* dst); | 149 static void Encode(int32_t codepoint, uint16_t* dst); |
| 152 | 150 |
| 153 static const int32_t kMaxCodeUnit = 0xFFFF; | 151 static const int32_t kMaxCodeUnit = 0xFFFF; |
| 154 | 152 |
| 155 private: | 153 private: |
| 156 static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10)); | 154 static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10)); |
| 157 | 155 |
| 158 static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00); | 156 static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00); |
| 159 }; | 157 }; |
| 160 | 158 |
| 161 | |
| 162 class CaseMapping : AllStatic { | 159 class CaseMapping : AllStatic { |
| 163 public: | 160 public: |
| 164 // Maps a code point to uppercase. | 161 // Maps a code point to uppercase. |
| 165 static int32_t ToUpper(int32_t code_point) { | 162 static int32_t ToUpper(int32_t code_point) { |
| 166 return Convert(code_point, kUppercase); | 163 return Convert(code_point, kUppercase); |
| 167 } | 164 } |
| 168 | 165 |
| 169 // Maps a code point to lowercase. | 166 // Maps a code point to lowercase. |
| 170 static int32_t ToLower(int32_t code_point) { | 167 static int32_t ToLower(int32_t code_point) { |
| 171 return Convert(code_point, kLowercase); | 168 return Convert(code_point, kLowercase); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // Data for small code points with one mapping | 215 // Data for small code points with one mapping |
| 219 static const int16_t stage2_[]; | 216 static const int16_t stage2_[]; |
| 220 | 217 |
| 221 // Data for large code points or code points with both mappings. | 218 // Data for large code points or code points with both mappings. |
| 222 static const int32_t stage2_exception_[][2]; | 219 static const int32_t stage2_exception_[][2]; |
| 223 }; | 220 }; |
| 224 | 221 |
| 225 } // namespace dart | 222 } // namespace dart |
| 226 | 223 |
| 227 #endif // RUNTIME_VM_UNICODE_H_ | 224 #endif // RUNTIME_VM_UNICODE_H_ |
| OLD | NEW |