summaryrefslogtreecommitdiff
path: root/base/i18n/case_conversion.h
blob: 2be9eb281d69b33fbf71caff13dcb822b5caf8e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_I18N_CASE_CONVERSION_H_
#define BASE_I18N_CASE_CONVERSION_H_

#include <string>
#include <string_view>

#include "base/i18n/base_i18n_export.h"

namespace base {
namespace i18n {

// UNICODE CASE-HANDLING ADVICE
//
// In English it's always safe to convert to upper-case or lower-case text
// and get a good answer. But some languages have rules specific to those
// locales. One example is the Turkish I:
//   http://www.i18nguy.com/unicode/turkish-i18n.html
//
// ToLower/ToUpper use the current ICU locale which will take into account
// the user language preference. Use this when dealing with user typing.
//
// FoldCase canonicalizes to a standardized form independent of the current
// locale. Use this when comparing general Unicode strings that don't
// necessarily belong in the user's current locale (like commands, protocol
// names, other strings from the web) for case-insensitive equality.
//
// Note that case conversions will change the length of the string in some
// not-uncommon cases. Never assume that the output is the same length as
// the input.

// Returns the lower case equivalent of string. Uses ICU's current locale.
BASE_I18N_EXPORT std::u16string ToLower(std::u16string_view string);

// Returns the upper case equivalent of string. Uses ICU's current locale.
BASE_I18N_EXPORT std::u16string ToUpper(std::u16string_view string);

// Convert the given string to a canonical case, independent of the current
// locale. For ASCII the canonical form is lower case.
// See http://unicode.org/faq/casemap_charprop.html#2
BASE_I18N_EXPORT std::u16string FoldCase(std::u16string_view string);

}  // namespace i18n
}  // namespace base

#endif  // BASE_I18N_CASE_CONVERSION_H_