string_compare.cc 1.0 KB

1234567891011121314151617181920212223242526272829
  1. // Copyright (c) 2013 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. #include "base/i18n/string_compare.h"
  5. #include "base/check.h"
  6. #include "base/strings/utf_string_conversions.h"
  7. #include "third_party/icu/source/common/unicode/unistr.h"
  8. namespace base {
  9. namespace i18n {
  10. // Compares the character data stored in two different std::u16string strings by
  11. // specified Collator instance.
  12. UCollationResult CompareString16WithCollator(const icu::Collator& collator,
  13. StringPiece16 lhs,
  14. StringPiece16 rhs) {
  15. UErrorCode error = U_ZERO_ERROR;
  16. UCollationResult result = collator.compare(
  17. icu::UnicodeString(false, lhs.data(), static_cast<int>(lhs.length())),
  18. icu::UnicodeString(false, rhs.data(), static_cast<int>(rhs.length())),
  19. error);
  20. DCHECK(U_SUCCESS(error));
  21. return result;
  22. }
  23. } // namespace i18n
  24. } // namespace base