xref: /aosp_15_r20/external/cronet/base/strings/latin1_string_conversions.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2013 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef BASE_STRINGS_LATIN1_STRING_CONVERSIONS_H_
6*6777b538SAndroid Build Coastguard Worker #define BASE_STRINGS_LATIN1_STRING_CONVERSIONS_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include <stddef.h>
9*6777b538SAndroid Build Coastguard Worker 
10*6777b538SAndroid Build Coastguard Worker #include <string>
11*6777b538SAndroid Build Coastguard Worker 
12*6777b538SAndroid Build Coastguard Worker #include "base/base_export.h"
13*6777b538SAndroid Build Coastguard Worker 
14*6777b538SAndroid Build Coastguard Worker namespace base {
15*6777b538SAndroid Build Coastguard Worker 
16*6777b538SAndroid Build Coastguard Worker // This definition of Latin1Char matches the definition of LChar in Blink. We
17*6777b538SAndroid Build Coastguard Worker // use unsigned char rather than char to make less tempting to mix and match
18*6777b538SAndroid Build Coastguard Worker // Latin-1 and UTF-8 characters..
19*6777b538SAndroid Build Coastguard Worker typedef unsigned char Latin1Char;
20*6777b538SAndroid Build Coastguard Worker 
21*6777b538SAndroid Build Coastguard Worker // This somewhat odd function is designed to help us convert from Blink Strings
22*6777b538SAndroid Build Coastguard Worker // to std::u16string. A Blink string is either backed by an array of Latin-1
23*6777b538SAndroid Build Coastguard Worker // characters or an array of UTF-16 characters. This function is called by
24*6777b538SAndroid Build Coastguard Worker // WebString::operator std::u16string() to convert one or the other character
25*6777b538SAndroid Build Coastguard Worker // array to std::u16string. This function is defined here rather than in
26*6777b538SAndroid Build Coastguard Worker // WebString.h to avoid binary bloat in all the callers of the conversion
27*6777b538SAndroid Build Coastguard Worker // operator.
28*6777b538SAndroid Build Coastguard Worker BASE_EXPORT std::u16string Latin1OrUTF16ToUTF16(size_t length,
29*6777b538SAndroid Build Coastguard Worker                                                 const Latin1Char* latin1,
30*6777b538SAndroid Build Coastguard Worker                                                 const char16_t* utf16);
31*6777b538SAndroid Build Coastguard Worker 
32*6777b538SAndroid Build Coastguard Worker }  // namespace base
33*6777b538SAndroid Build Coastguard Worker 
34*6777b538SAndroid Build Coastguard Worker #endif  // BASE_STRINGS_LATIN1_STRING_CONVERSIONS_H_
35