• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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  *     http://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 
16 #ifndef COMMON_INTERFACES_OBJECTS_UTILS_UTF_H
17 #define COMMON_INTERFACES_OBJECTS_UTILS_UTF_H
18 
19 #include <cstddef>
20 #include <cstdint>
21 
22 namespace common {
23 class BaseString;
24 
25 class UtfUtils {
26 private:
27     static constexpr uint8_t UTF8_1B_MAX = 0x7f;
28     static size_t DebuggerConvertRegionUtf16ToUtf8(const uint16_t *utf16In, uint8_t *utf8Out, size_t utf16Len,
29                                                    size_t utf8Len, size_t start, bool modify = true,
30                                                    bool isWriteBuffer = false);
31 
32     static size_t Utf8ToUtf16Size(const uint8_t *utf8, size_t utf8Len);
33 
34     static size_t Utf16ToUtf8Size(const uint16_t *utf16, uint32_t length, bool modify = true,
35                                   bool isGetBufferSize = false, bool cesu8 = false);
36 
37     static size_t ConvertRegionUtf8ToUtf16(const uint8_t *utf8In, uint16_t *utf16Out, size_t utf8Len, size_t utf16Len);
38 
39     static size_t ConvertRegionUtf16ToLatin1(const uint16_t *utf16In, uint8_t *latin1Out, size_t utf16Len,
40                                              size_t latin1Len);
41 
42     static size_t ConvertRegionUtf16ToUtf8(const uint16_t *utf16In, uint8_t *utf8Out, size_t utf16Len,
43                                            size_t utf8Len, size_t start, bool modify = true, bool isWriteBuffer = false,
44                                            bool cesu = false);
45 
46     friend BaseString;
47 };
48 } // namespace common
49 #endif  // COMMON_INTERFACES_OBJECTS_UTILS_UTF_H