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

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: Self review. 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 // Use "base/memory/scoped_ptr.h" instead.
6 #define I18N_ADDRESSINPUT_UTIL_SCOPED_PTR_H_
7
8 #include "base/basictypes.h"
9 #include "base/logging.h"
10 // Must be before string_compare.h to be used in the StringCompare class.
11 #include "base/memory/scoped_ptr.h"
12 #include "third_party/icu/source/common/unicode/errorcode.h"
13 #include "third_party/icu/source/common/unicode/locid.h"
14 #include "third_party/icu/source/common/unicode/unistr.h"
15 #include "third_party/icu/source/common/unicode/utypes.h"
16 #include "third_party/icu/source/i18n/unicode/coll.h"
17 #include "third_party/libaddressinput/src/cpp/src/util/string_compare.h"
18
19 namespace i18n {
20 namespace addressinput {
21
22 class StringCompare::Impl {
23 public:
24 Impl() {
25 UErrorCode error_code = U_ZERO_ERROR;
26 collator_.reset(icu::Collator::createInstance(
27 icu::Locale::getRoot(), error_code));
28 DCHECK(U_SUCCESS(error_code));
29 collator_->setStrength(icu::Collator::PRIMARY);
30 }
31
32 ~Impl() {}
33
34 bool NaturalEquals(const std::string& a, const std::string& b) const {
35 UErrorCode error_code = U_ZERO_ERROR;
36 bool equal = collator_->compareUTF8(a, b, error_code) == 0;
37 DCHECK(U_SUCCESS(error_code));
38 return equal;
39 }
40
41 private:
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