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 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 return 0xb5; | 88 return 0xb5; |
89 // This is an uppercase of a Latin-1 character | 89 // This is an uppercase of a Latin-1 character |
90 // outside of Latin-1. | 90 // outside of Latin-1. |
91 case 0x178: | 91 case 0x178: |
92 return 0xff; | 92 return 0xff; |
93 } | 93 } |
94 return 0; | 94 return 0; |
95 } | 95 } |
96 | 96 |
97 | 97 |
| 98 unsigned Utf8::EncodeOneByte(char* str, uint8_t c) { |
| 99 static const int kMask = ~(1 << 6); |
| 100 if (c <= kMaxOneByteChar) { |
| 101 str[0] = c; |
| 102 return 1; |
| 103 } |
| 104 str[0] = 0xC0 | (c >> 6); |
| 105 str[1] = 0x80 | (c & kMask); |
| 106 return 2; |
| 107 } |
| 108 |
| 109 |
98 unsigned Utf8::Encode(char* str, uchar c, int previous) { | 110 unsigned Utf8::Encode(char* str, uchar c, int previous) { |
99 static const int kMask = ~(1 << 6); | 111 static const int kMask = ~(1 << 6); |
100 if (c <= kMaxOneByteChar) { | 112 if (c <= kMaxOneByteChar) { |
101 str[0] = c; | 113 str[0] = c; |
102 return 1; | 114 return 1; |
103 } else if (c <= kMaxTwoByteChar) { | 115 } else if (c <= kMaxTwoByteChar) { |
104 str[0] = 0xC0 | (c >> 6); | 116 str[0] = 0xC0 | (c >> 6); |
105 str[1] = 0x80 | (c & kMask); | 117 str[1] = 0x80 | (c & kMask); |
106 return 2; | 118 return 2; |
107 } else if (c <= kMaxThreeByteChar) { | 119 } else if (c <= kMaxThreeByteChar) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // Copy the rest the slow way. | 208 // Copy the rest the slow way. |
197 WriteUtf16Slow(unbuffered_start_, | 209 WriteUtf16Slow(unbuffered_start_, |
198 data + buffer_length, | 210 data + buffer_length, |
199 length - buffer_length); | 211 length - buffer_length); |
200 return length; | 212 return length; |
201 } | 213 } |
202 | 214 |
203 } // namespace unibrow | 215 } // namespace unibrow |
204 | 216 |
205 #endif // V8_UNICODE_INL_H_ | 217 #endif // V8_UNICODE_INL_H_ |
OLD | NEW |