1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MEDIAPROVIDER_PDF_JNI_PDFCLIENT_UTF_H_
18 #define MEDIAPROVIDER_PDF_JNI_PDFCLIENT_UTF_H_
19 
20 #include <string>
21 
22 namespace std {
23 // Typedef std::u16string and std::u32string in case they are missing.
24 typedef std::basic_string<char16_t> u16string;
25 typedef std::basic_string<char32_t> u32string;
26 }  // namespace std
27 
28 namespace pdfClient {
29 
30 // Converts a string from UTF-8 to UTF-32.
31 std::u32string Utf8ToUtf32(std::string_view utf8);
32 
33 // Converts a C-string from UTF-8 to UTF-32.
34 std::u32string Utf8ToUtf32(const char* utf8);
35 
36 // Converts a string from UTF-16 to UTF-8.
37 std::string Utf16ToUtf8(const std::u16string& utf16);
38 
39 // Converts an individual unicode codepoint to one or more UTF-8 chars,
40 // and appends them to the output string.
41 void AppendCodepointAsUtf8(const char32_t codepoint, std::string* output);
42 
43 // If a C-string is copied directly into a string, it can end up with a trailing
44 // '\0' character. This trims it.
45 void EraseTrailingNulls(std::string* str);
46 
47 }  // namespace pdfClient
48 
49 #endif  // MEDIAPROVIDER_PDF_JNI_PDFCLIENT_UTF_H_