unicodestring.h 997 B

1234567891011121314151617181920212223242526272829303132
  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. #ifndef BASE_I18N_UNICODESTRING_H_
  5. #define BASE_I18N_UNICODESTRING_H_
  6. #include "base/strings/string16.h"
  7. #include "third_party/icu/source/common/unicode/unistr.h"
  8. #include "third_party/icu/source/common/unicode/uvernum.h"
  9. #if U_ICU_VERSION_MAJOR_NUM >= 59
  10. #include "third_party/icu/source/common/unicode/char16ptr.h"
  11. #endif
  12. namespace base {
  13. namespace i18n {
  14. inline string16 UnicodeStringToString16(const icu::UnicodeString& unistr) {
  15. #if U_ICU_VERSION_MAJOR_NUM >= 59
  16. return base::string16(icu::toUCharPtr(unistr.getBuffer()),
  17. static_cast<size_t>(unistr.length()));
  18. #else
  19. return base::string16(unistr.getBuffer(),
  20. static_cast<size_t>(unistr.length()));
  21. #endif
  22. }
  23. } // namespace i18n
  24. } // namespace base
  25. #endif // BASE_UNICODESTRING_H_