1 // Copyright 2017 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_UNICODESTRING_H_ 6 #define BASE_I18N_UNICODESTRING_H_ 7 8 #include <string> 9 10 #include "third_party/icu/source/common/unicode/unistr.h" 11 #include "third_party/icu/source/common/unicode/uvernum.h" 12 13 #if U_ICU_VERSION_MAJOR_NUM >= 59 14 #include "third_party/icu/source/common/unicode/char16ptr.h" 15 #endif 16 17 namespace base { 18 namespace i18n { 19 UnicodeStringToString16(const icu::UnicodeString & unistr)20inline std::u16string UnicodeStringToString16( 21 const icu::UnicodeString& unistr) { 22 #if U_ICU_VERSION_MAJOR_NUM >= 59 23 return std::u16string(icu::toUCharPtr(unistr.getBuffer()), 24 static_cast<size_t>(unistr.length())); 25 #else 26 return std::u16string(unistr.getBuffer(), 27 static_cast<size_t>(unistr.length())); 28 #endif 29 } 30 31 } // namespace i18n 32 } // namespace base 33 34 #endif // BASE_I18N_UNICODESTRING_H_ 35