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

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: Work in progress for suggestions impl. Created 6 years, 6 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 #include "third_party/libaddressinput/src/cpp/src/util/string_compare.h"
6
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "third_party/icu/source/common/unicode/errorcode.h"
11 #include "third_party/icu/source/common/unicode/locid.h"
12 #include "third_party/icu/source/common/unicode/unistr.h"
13 #include "third_party/icu/source/common/unicode/utypes.h"
14 #include "third_party/icu/source/i18n/unicode/coll.h"
15
16 namespace i18n {
17 namespace addressinput {
18
19 class StringCompare::Impl {
20 public:
21 Impl() {
22 UErrorCode error_code = U_ZERO_ERROR;
23 collator_.reset(icu::Collator::createInstance(
24 icu::Locale::getRoot(), error_code));
25 DCHECK(U_SUCCESS(error_code));
26 collator_->setStrength(icu::Collator::PRIMARY);
27 }
28
29 ~Impl() {}
30
31 bool NaturalEquals(const std::string& a, const std::string& b) const {
32 UErrorCode error_code = U_ZERO_ERROR;
33 bool equal = collator_->compareUTF8(a, b, error_code) == 0;
34 DCHECK(U_SUCCESS(error_code));
35 return equal;
36 }
37
38 private:
39 // ::scoped_ptr is from "base/memory/scoped_ptr.h", which does not interfere
40 // with ::i18n::addressinput::scoped_ptr from
41 // <libaddressinput/util/scoped_ptr.h>.
42 ::scoped_ptr<icu::Collator> collator_;
43
44 DISALLOW_COPY_AND_ASSIGN(Impl);
45 };
46
47 StringCompare::StringCompare() : impl_(new Impl) {}
48
49 StringCompare::~StringCompare() {}
50
51 bool StringCompare::NaturalEquals(const std::string& a,
52 const std::string& b) const {
53 return impl_->NaturalEquals(a, b);
54 }
55
56 } // namespace addressinput
57 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698