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