xref: /aosp_15_r20/external/cronet/net/base/net_string_util.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2014 The Chromium Authors
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 NET_BASE_NET_STRING_UTIL_H__
6 #define NET_BASE_NET_STRING_UTIL_H__
7 
8 #include <string>
9 
10 #include "base/strings/string_piece.h"
11 #include "net/base/net_export.h"
12 
13 // String conversion functions.  By default, they're implemented with ICU, but
14 // when building with USE_ICU_ALTERNATIVES, they use platform functions instead.
15 
16 namespace net {
17 
18 extern const char* const kCharsetLatin1;
19 
20 // Converts |text| using |charset| to UTF-8, and writes it to |output|.
21 // On failure, returns false and |output| is cleared.
22 bool ConvertToUtf8(std::string_view text,
23                    const char* charset,
24                    std::string* output);
25 
26 // Converts |text| using |charset| to UTF-8, normalizes the result, and writes
27 // it to |output|.  On failure, returns false and |output| is cleared.
28 bool ConvertToUtf8AndNormalize(std::string_view text,
29                                const char* charset,
30                                std::string* output);
31 
32 // Converts |text| using |charset| to UTF-16, and writes it to |output|.
33 // On failure, returns false and |output| is cleared.
34 bool ConvertToUTF16(std::string_view text,
35                     const char* charset,
36                     std::u16string* output);
37 
38 // Converts |text| using |charset| to UTF-16, and writes it to |output|.
39 // Any characters that can not be converted are replaced with U+FFFD.
40 bool ConvertToUTF16WithSubstitutions(std::string_view text,
41                                      const char* charset,
42                                      std::u16string* output);
43 
44 // Converts |str| to uppercase using the default locale, and writes it to
45 // |output|. On failure returns false and |output| is cleared.
46 NET_EXPORT_PRIVATE bool ToUpper(std::u16string_view str,
47                                 std::u16string* output);
48 
49 }  // namespace net
50 
51 #endif  // NET_BASE_NET_STRING_UTIL_H__
52