1 // Copyright (c) 2011 The Chromium 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 BASE_STRINGS_UTF_STRING_CONVERSIONS_H_ 6 #define BASE_STRINGS_UTF_STRING_CONVERSIONS_H_ 7 8 #include <stddef.h> 9 10 #include <string> 11 #include <string_view> 12 13 namespace base { 14 15 bool UTF8ToUTF16(const char* src, size_t src_len, std::u16string* output); 16 std::u16string UTF8ToUTF16(std::string_view utf8); 17 bool UTF16ToUTF8(const char16_t* src, size_t src_len, std::string* output); 18 std::string UTF16ToUTF8(std::u16string_view utf16); 19 20 // This converts an ASCII string, typically a hardcoded constant, to a UTF16 21 // string. 22 std::u16string ASCIIToUTF16(std::string_view ascii); 23 24 // Converts to 7-bit ASCII by truncating. The result must be known to be ASCII 25 // beforehand. 26 std::string UTF16ToASCII(std::u16string_view utf16); 27 28 } // namespace base 29 30 #endif // BASE_STRINGS_UTF_STRING_CONVERSIONS_H_ 31