Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: third_party/libaddressinput/chromium/string_compare.cc

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 // Use "base/basictypes.h" instead.
6 #define I18N_ADDRESSINPUT_UTIL_BASICTYPES_H_
7
8 // Use "base/memory/scoped_ptr.h" instead.
9 #define I18N_ADDRESSINPUT_UTIL_SCOPED_PTR_H_
10
11 #include "base/basictypes.h"
12 #include "base/logging.h"
13 // Must be before string_compare.h to be used in the StringCompare class.
14 #include "base/memory/scoped_ptr.h"
15 #include "third_party/icu/source/common/unicode/errorcode.h"
16 #include "third_party/icu/source/common/unicode/locid.h"
17 #include "third_party/icu/source/common/unicode/unistr.h"
18 #include "third_party/icu/source/common/unicode/utypes.h"
19 #include "third_party/icu/source/i18n/unicode/coll.h"
20 #include "third_party/libaddressinput/src/cpp/src/util/string_compare.h"
21
22 namespace i18n {
23 namespace addressinput {
24
25 class StringCompare::Impl {
26 public:
27 Impl() {
28 UErrorCode error_code = U_ZERO_ERROR;
29 collator_.reset(icu::Collator::createInstance(
30 icu::Locale::getRoot(), error_code));
31 DCHECK(U_SUCCESS(error_code));
32 collator_->setStrength(icu::Collator::PRIMARY);
33 }
34
35 ~Impl() {}
36
37 bool NaturalEquals(const std::string& a, const std::string& b) const {
38 UErrorCode error_code = U_ZERO_ERROR;
39 bool equal = collator_->compareUTF8(a, b, error_code) == 0;
40 DCHECK(U_SUCCESS(error_code));
41 return equal;
42 }
43
44 private:
45 scoped_ptr<icu::Collator> collator_;
46
47 DISALLOW_COPY_AND_ASSIGN(Impl);
48 };
49
50 StringCompare::StringCompare() : impl_(new Impl) {}
51
52 StringCompare::~StringCompare() {}
53
54 bool StringCompare::NaturalEquals(const std::string& a,
55 const std::string& b) const {
56 return impl_->NaturalEquals(a, b);
57 }
58
59 } // namespace addressinput
60 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698