Line data Source code
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 2533707 : if (c == unibrow::Utf8::kIncomplete || c == unibrow::Utf8::kBufferEmpty) {
12 : return 0;
13 2463965 : } else if (c < 0xffff) {
14 : return 1;
15 : } else {
16 : return 2;
17 : }
18 : }
19 :
20 69677 : static int Utf8LengthHelper(const char* s) {
21 69677 : unibrow::Utf8::Utf8IncrementalBuffer buffer(unibrow::Utf8::kBufferEmpty);
22 : int length = 0;
23 2533707 : for (; *s != '\0'; s++) {
24 2464030 : unibrow::uchar tmp = unibrow::Utf8::ValueOfIncremental(*s, &buffer);
25 2464030 : length += Ucs2CharLength(tmp);
26 : }
27 69677 : unibrow::uchar tmp = unibrow::Utf8::ValueOfIncrementalFinish(&buffer);
28 69677 : length += Ucs2CharLength(tmp);
29 69677 : return length;
30 : }
31 :
32 : #endif // V8_CCTEST_UNICODE_HELPERS_H_
|