| OLD | NEW |
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_UNICODE_INL_H_ | 5 #ifndef V8_UNICODE_INL_H_ |
| 6 #define V8_UNICODE_INL_H_ | 6 #define V8_UNICODE_INL_H_ |
| 7 | 7 |
| 8 #include "src/unicode.h" | 8 #include "src/unicode.h" |
| 9 #include "src/base/logging.h" | 9 #include "src/base/logging.h" |
| 10 #include "src/utils.h" | 10 #include "src/utils.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } else { | 103 } else { |
| 104 str[0] = 0xF0 | (c >> 18); | 104 str[0] = 0xF0 | (c >> 18); |
| 105 str[1] = 0x80 | ((c >> 12) & kMask); | 105 str[1] = 0x80 | ((c >> 12) & kMask); |
| 106 str[2] = 0x80 | ((c >> 6) & kMask); | 106 str[2] = 0x80 | ((c >> 6) & kMask); |
| 107 str[3] = 0x80 | (c & kMask); | 107 str[3] = 0x80 | (c & kMask); |
| 108 return 4; | 108 return 4; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 | 112 |
| 113 uchar Utf8::ValueOf(const byte* bytes, unsigned length, unsigned* cursor) { | 113 uchar Utf8::ValueOf(const byte* bytes, size_t length, size_t* cursor) { |
| 114 if (length <= 0) return kBadChar; | 114 if (length <= 0) return kBadChar; |
| 115 byte first = bytes[0]; | 115 byte first = bytes[0]; |
| 116 // Characters between 0000 and 0007F are encoded as a single character | 116 // Characters between 0000 and 0007F are encoded as a single character |
| 117 if (first <= kMaxOneByteChar) { | 117 if (first <= kMaxOneByteChar) { |
| 118 *cursor += 1; | 118 *cursor += 1; |
| 119 return first; | 119 return first; |
| 120 } | 120 } |
| 121 return CalculateValue(bytes, length, cursor); | 121 return CalculateValue(bytes, length, cursor); |
| 122 } | 122 } |
| 123 | 123 |
| 124 unsigned Utf8::Length(uchar c, int previous) { | 124 unsigned Utf8::Length(uchar c, int previous) { |
| 125 if (c <= kMaxOneByteChar) { | 125 if (c <= kMaxOneByteChar) { |
| 126 return 1; | 126 return 1; |
| 127 } else if (c <= kMaxTwoByteChar) { | 127 } else if (c <= kMaxTwoByteChar) { |
| 128 return 2; | 128 return 2; |
| 129 } else if (c <= kMaxThreeByteChar) { | 129 } else if (c <= kMaxThreeByteChar) { |
| 130 if (Utf16::IsTrailSurrogate(c) && | 130 if (Utf16::IsTrailSurrogate(c) && |
| 131 Utf16::IsLeadSurrogate(previous)) { | 131 Utf16::IsLeadSurrogate(previous)) { |
| 132 return kSizeOfUnmatchedSurrogate - kBytesSavedByCombiningSurrogates; | 132 return kSizeOfUnmatchedSurrogate - kBytesSavedByCombiningSurrogates; |
| 133 } | 133 } |
| 134 return 3; | 134 return 3; |
| 135 } else { | 135 } else { |
| 136 return 4; | 136 return 4; |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace unibrow | 140 } // namespace unibrow |
| 141 | 141 |
| 142 #endif // V8_UNICODE_INL_H_ | 142 #endif // V8_UNICODE_INL_H_ |
| OLD | NEW |