xref: /aosp_15_r20/external/libchrome/base/i18n/unicodestring.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved.
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_UNICODESTRING_H_
6 #define BASE_I18N_UNICODESTRING_H_
7 
8 #include "base/strings/string16.h"
9 #include "third_party/icu/source/common/unicode/unistr.h"
10 #include "third_party/icu/source/common/unicode/uvernum.h"
11 
12 #if U_ICU_VERSION_MAJOR_NUM >= 59
13 #include "third_party/icu/source/common/unicode/char16ptr.h"
14 #endif
15 
16 namespace base {
17 namespace i18n {
18 
UnicodeStringToString16(const icu::UnicodeString & unistr)19 inline string16 UnicodeStringToString16(const icu::UnicodeString& unistr) {
20 #if U_ICU_VERSION_MAJOR_NUM >= 59
21   return base::string16(icu::toUCharPtr(unistr.getBuffer()),
22                         static_cast<size_t>(unistr.length()));
23 #else
24   return base::string16(unistr.getBuffer(),
25                         static_cast<size_t>(unistr.length()));
26 #endif
27 }
28 
29 }  // namespace i18n
30 }  // namespace base
31 
32 #endif  // BASE_UNICODESTRING_H_
33