OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_CCTEST_UNICODE_HELPERS_H_ |
| 6 #define V8_CCTEST_UNICODE_HELPERS_H_ |
| 7 |
| 8 #include "src/unicode.h" |
| 9 |
| 10 static int Ucs2CharLength(unibrow::uchar c) { |
| 11 if (c == unibrow::Utf8::kIncomplete || c == unibrow::Utf8::kBufferEmpty) { |
| 12 return 0; |
| 13 } else if (c < 0xffff) { |
| 14 return 1; |
| 15 } else { |
| 16 return 2; |
| 17 } |
| 18 } |
| 19 |
| 20 static int Utf8LengthHelper(const char* s) { |
| 21 unibrow::Utf8::Utf8IncrementalBuffer buffer(unibrow::Utf8::kBufferEmpty); |
| 22 int length = 0; |
| 23 for (; *s != '\0'; s++) { |
| 24 unibrow::uchar tmp = unibrow::Utf8::ValueOfIncremental(*s, &buffer); |
| 25 length += Ucs2CharLength(tmp); |
| 26 } |
| 27 unibrow::uchar tmp = unibrow::Utf8::ValueOfIncrementalFinish(&buffer); |
| 28 length += Ucs2CharLength(tmp); |
| 29 return length; |
| 30 } |
| 31 |
| 32 #endif // V8_CCTEST_UNICODE_HELPERS_H_ |
OLD | NEW |