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

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: Rebase on top of https://codereview.chromium.org/359213002/ Created 6 years, 5 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/i18n/unicode/coll.h"
11
12 namespace i18n {
13 namespace addressinput {
14
15 class StringCompare::Impl {
Evan Stade 2014/06/30 18:49:38 Why is this class an inner class of StringCompare
please use gerrit instead 2014/07/01 04:53:50 Done.
16 public:
17 Impl() {}
18
19 ~Impl() {}
20
21 bool NaturalEquals(const std::string& a, const std::string& b) const {
22 return NaturalCompare(a, b) == 0;
23 }
24
25 bool NaturalLess(const std::string& a, const std::string& b) const {
26 return NaturalCompare(a, b) < 0;
27 }
28
29 private:
30 int NaturalCompare(const std::string& a, const std::string& b) const {
31 UErrorCode error_code = U_ZERO_ERROR;
32 if (!collator_) {
33 collator_.reset(
34 icu::Collator::createInstance(icu::Locale::getRoot(), error_code));
35 DCHECK(U_SUCCESS(error_code));
36 collator_->setStrength(icu::Collator::PRIMARY);
37 }
38 error_code = U_ZERO_ERROR;
39 int result = collator_->compareUTF8(a, b, error_code);
40 DCHECK(U_SUCCESS(error_code));
41 return result;
42 }
43
44 // ::scoped_ptr is from "base/memory/scoped_ptr.h", which does not interfere
45 // with ::i18n::addressinput::scoped_ptr from
46 // <libaddressinput/util/scoped_ptr.h>.
47 mutable ::scoped_ptr<icu::Collator> collator_;
48
49 DISALLOW_COPY_AND_ASSIGN(Impl);
50 };
51
52 StringCompare::StringCompare() : impl_(new Impl) {
Evan Stade 2014/06/30 18:49:38 nit: {} on one line
please use gerrit instead 2014/07/01 04:53:50 Done. (I have to remember to fix this after every
53 }
54
55 StringCompare::~StringCompare() {
Evan Stade 2014/06/30 18:49:38 nit: {} on one line
please use gerrit instead 2014/07/01 04:53:50 Done.
56 }
57
58 bool StringCompare::NaturalEquals(const std::string& a,
59 const std::string& b) const {
60 return impl_->NaturalEquals(a, b);
61 }
62
63 bool StringCompare::NaturalLess(const std::string& a,
64 const std::string& b) const {
65 return impl_->NaturalLess(a, b);
66 }
67
68 } // namespace addressinput
69 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698