xref: /aosp_15_r20/external/cronet/base/i18n/case_conversion.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2011 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 BASE_I18N_CASE_CONVERSION_H_
6 #define BASE_I18N_CASE_CONVERSION_H_
7 
8 #include <string>
9 #include <string_view>
10 
11 #include "base/i18n/base_i18n_export.h"
12 
13 namespace base {
14 namespace i18n {
15 
16 // UNICODE CASE-HANDLING ADVICE
17 //
18 // In English it's always safe to convert to upper-case or lower-case text
19 // and get a good answer. But some languages have rules specific to those
20 // locales. One example is the Turkish I:
21 //   http://www.i18nguy.com/unicode/turkish-i18n.html
22 //
23 // ToLower/ToUpper use the current ICU locale which will take into account
24 // the user language preference. Use this when dealing with user typing.
25 //
26 // FoldCase canonicalizes to a standardized form independent of the current
27 // locale. Use this when comparing general Unicode strings that don't
28 // necessarily belong in the user's current locale (like commands, protocol
29 // names, other strings from the web) for case-insensitive equality.
30 //
31 // Note that case conversions will change the length of the string in some
32 // not-uncommon cases. Never assume that the output is the same length as
33 // the input.
34 
35 // Returns the lower case equivalent of string. Uses ICU's current locale.
36 BASE_I18N_EXPORT std::u16string ToLower(std::u16string_view string);
37 
38 // Returns the upper case equivalent of string. Uses ICU's current locale.
39 BASE_I18N_EXPORT std::u16string ToUpper(std::u16string_view string);
40 
41 // Convert the given string to a canonical case, independent of the current
42 // locale. For ASCII the canonical form is lower case.
43 // See http://unicode.org/faq/casemap_charprop.html#2
44 BASE_I18N_EXPORT std::u16string FoldCase(std::u16string_view string);
45 
46 }  // namespace i18n
47 }  // namespace base
48 
49 #endif  // BASE_I18N_CASE_CONVERSION_H_
50