xref: /aosp_15_r20/external/libchrome/base/i18n/case_conversion.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef BASE_I18N_CASE_CONVERSION_H_
6*635a8641SAndroid Build Coastguard Worker #define BASE_I18N_CASE_CONVERSION_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include "base/i18n/base_i18n_export.h"
9*635a8641SAndroid Build Coastguard Worker #include "base/strings/string16.h"
10*635a8641SAndroid Build Coastguard Worker #include "base/strings/string_piece.h"
11*635a8641SAndroid Build Coastguard Worker 
12*635a8641SAndroid Build Coastguard Worker namespace base {
13*635a8641SAndroid Build Coastguard Worker namespace i18n {
14*635a8641SAndroid Build Coastguard Worker 
15*635a8641SAndroid Build Coastguard Worker // UNICODE CASE-HANDLING ADVICE
16*635a8641SAndroid Build Coastguard Worker //
17*635a8641SAndroid Build Coastguard Worker // In English it's always safe to convert to upper-case or lower-case text
18*635a8641SAndroid Build Coastguard Worker // and get a good answer. But some languages have rules specific to those
19*635a8641SAndroid Build Coastguard Worker // locales. One example is the Turkish I:
20*635a8641SAndroid Build Coastguard Worker //   http://www.i18nguy.com/unicode/turkish-i18n.html
21*635a8641SAndroid Build Coastguard Worker //
22*635a8641SAndroid Build Coastguard Worker // ToLower/ToUpper use the current ICU locale which will take into account
23*635a8641SAndroid Build Coastguard Worker // the user language preference. Use this when dealing with user typing.
24*635a8641SAndroid Build Coastguard Worker //
25*635a8641SAndroid Build Coastguard Worker // FoldCase canonicalizes to a standardized form independent of the current
26*635a8641SAndroid Build Coastguard Worker // locale. Use this when comparing general Unicode strings that don't
27*635a8641SAndroid Build Coastguard Worker // necessarily belong in the user's current locale (like commands, protocol
28*635a8641SAndroid Build Coastguard Worker // names, other strings from the web) for case-insensitive equality.
29*635a8641SAndroid Build Coastguard Worker //
30*635a8641SAndroid Build Coastguard Worker // Note that case conversions will change the length of the string in some
31*635a8641SAndroid Build Coastguard Worker // not-uncommon cases. Never assume that the output is the same length as
32*635a8641SAndroid Build Coastguard Worker // the input.
33*635a8641SAndroid Build Coastguard Worker 
34*635a8641SAndroid Build Coastguard Worker // Returns the lower case equivalent of string. Uses ICU's current locale.
35*635a8641SAndroid Build Coastguard Worker BASE_I18N_EXPORT string16 ToLower(StringPiece16 string);
36*635a8641SAndroid Build Coastguard Worker 
37*635a8641SAndroid Build Coastguard Worker // Returns the upper case equivalent of string. Uses ICU's current locale.
38*635a8641SAndroid Build Coastguard Worker BASE_I18N_EXPORT string16 ToUpper(StringPiece16 string);
39*635a8641SAndroid Build Coastguard Worker 
40*635a8641SAndroid Build Coastguard Worker // Convert the given string to a canonical case, independent of the current
41*635a8641SAndroid Build Coastguard Worker // locale. For ASCII the canonical form is lower case.
42*635a8641SAndroid Build Coastguard Worker // See http://unicode.org/faq/casemap_charprop.html#2
43*635a8641SAndroid Build Coastguard Worker BASE_I18N_EXPORT string16 FoldCase(StringPiece16 string);
44*635a8641SAndroid Build Coastguard Worker 
45*635a8641SAndroid Build Coastguard Worker }  // namespace i18n
46*635a8641SAndroid Build Coastguard Worker }  // namespace base
47*635a8641SAndroid Build Coastguard Worker 
48*635a8641SAndroid Build Coastguard Worker #endif  // BASE_I18N_CASE_CONVERSION_H_
49