/proc/self/cwd/external/com_google_absl/absl/strings/internal/utf8.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2017 The Abseil Authors. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | // UTF8 utilities, implemented to reduce dependencies. |
16 | | |
17 | | #include "absl/strings/internal/utf8.h" |
18 | | |
19 | | namespace absl { |
20 | | ABSL_NAMESPACE_BEGIN |
21 | | namespace strings_internal { |
22 | | |
23 | 0 | size_t EncodeUTF8Char(char *buffer, char32_t utf8_char) { |
24 | 0 | if (utf8_char <= 0x7F) { |
25 | 0 | *buffer = static_cast<char>(utf8_char); |
26 | 0 | return 1; |
27 | 0 | } else if (utf8_char <= 0x7FF) { |
28 | 0 | buffer[1] = static_cast<char>(0x80 | (utf8_char & 0x3F)); |
29 | 0 | utf8_char >>= 6; |
30 | 0 | buffer[0] = static_cast<char>(0xC0 | utf8_char); |
31 | 0 | return 2; |
32 | 0 | } else if (utf8_char <= 0xFFFF) { |
33 | 0 | buffer[2] = static_cast<char>(0x80 | (utf8_char & 0x3F)); |
34 | 0 | utf8_char >>= 6; |
35 | 0 | buffer[1] = static_cast<char>(0x80 | (utf8_char & 0x3F)); |
36 | 0 | utf8_char >>= 6; |
37 | 0 | buffer[0] = static_cast<char>(0xE0 | utf8_char); |
38 | 0 | return 3; |
39 | 0 | } else { |
40 | 0 | buffer[3] = static_cast<char>(0x80 | (utf8_char & 0x3F)); |
41 | 0 | utf8_char >>= 6; |
42 | 0 | buffer[2] = static_cast<char>(0x80 | (utf8_char & 0x3F)); |
43 | 0 | utf8_char >>= 6; |
44 | 0 | buffer[1] = static_cast<char>(0x80 | (utf8_char & 0x3F)); |
45 | 0 | utf8_char >>= 6; |
46 | 0 | buffer[0] = static_cast<char>(0xF0 | utf8_char); |
47 | 0 | return 4; |
48 | 0 | } |
49 | 0 | } |
50 | | |
51 | | } // namespace strings_internal |
52 | | ABSL_NAMESPACE_END |
53 | | } // namespace absl |