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

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

Issue 1911823002: Convert //third_party from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update crashpad's README.chromium Created 4 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "third_party/libaddressinput/src/cpp/src/util/string_compare.h" 5 #include "third_party/libaddressinput/src/cpp/src/util/string_compare.h"
6 6
7 #include <memory>
8
7 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "third_party/icu/source/i18n/unicode/coll.h" 12 #include "third_party/icu/source/i18n/unicode/coll.h"
12 13
13 namespace i18n { 14 namespace i18n {
14 namespace addressinput { 15 namespace addressinput {
15 16
16 namespace { 17 namespace {
17 18
18 class IcuStringComparer { 19 class IcuStringComparer {
19 public: 20 public:
20 IcuStringComparer() { 21 IcuStringComparer() {
21 UErrorCode error_code = U_ZERO_ERROR; 22 UErrorCode error_code = U_ZERO_ERROR;
22 collator_.reset( 23 collator_.reset(
23 icu::Collator::createInstance(icu::Locale::getRoot(), error_code)); 24 icu::Collator::createInstance(icu::Locale::getRoot(), error_code));
24 DCHECK(U_SUCCESS(error_code)); 25 DCHECK(U_SUCCESS(error_code));
25 collator_->setStrength(icu::Collator::PRIMARY); 26 collator_->setStrength(icu::Collator::PRIMARY);
26 } 27 }
27 28
28 ~IcuStringComparer() {} 29 ~IcuStringComparer() {}
29 30
30 int Compare(const std::string& a, const std::string& b) const { 31 int Compare(const std::string& a, const std::string& b) const {
31 UErrorCode error_code = U_ZERO_ERROR; 32 UErrorCode error_code = U_ZERO_ERROR;
32 int result = collator_->compareUTF8(a, b, error_code); 33 int result = collator_->compareUTF8(a, b, error_code);
33 DCHECK(U_SUCCESS(error_code)); 34 DCHECK(U_SUCCESS(error_code));
34 return result; 35 return result;
35 } 36 }
36 37
37 private: 38 private:
38 // ::scoped_ptr is from "base/memory/scoped_ptr.h", which does not interfere 39 std::unique_ptr<icu::Collator> collator_;
39 // with ::i18n::addressinput::scoped_ptr from
40 // <libaddressinput/util/scoped_ptr.h>.
41 ::scoped_ptr<icu::Collator> collator_;
42 40
43 DISALLOW_COPY_AND_ASSIGN(IcuStringComparer); 41 DISALLOW_COPY_AND_ASSIGN(IcuStringComparer);
44 }; 42 };
45 43
46 static base::LazyInstance<IcuStringComparer> g_comparer = 44 static base::LazyInstance<IcuStringComparer> g_comparer =
47 LAZY_INSTANCE_INITIALIZER; 45 LAZY_INSTANCE_INITIALIZER;
48 46
49 } // namespace 47 } // namespace
50 48
51 // Dummy required for scoped_ptr<Impl>. 49 // Dummy required for std::unique_ptr<Impl>.
52 class StringCompare::Impl {}; 50 class StringCompare::Impl {};
53 51
54 StringCompare::StringCompare() {} 52 StringCompare::StringCompare() {}
55 53
56 StringCompare::~StringCompare() {} 54 StringCompare::~StringCompare() {}
57 55
58 bool StringCompare::NaturalEquals(const std::string& a, 56 bool StringCompare::NaturalEquals(const std::string& a,
59 const std::string& b) const { 57 const std::string& b) const {
60 return g_comparer.Get().Compare(a, b) == 0; 58 return g_comparer.Get().Compare(a, b) == 0;
61 } 59 }
62 60
63 bool StringCompare::NaturalLess(const std::string& a, 61 bool StringCompare::NaturalLess(const std::string& a,
64 const std::string& b) const { 62 const std::string& b) const {
65 return g_comparer.Get().Compare(a, b) < 0; 63 return g_comparer.Get().Compare(a, b) < 0;
66 } 64 }
67 65
68 } // namespace addressinput 66 } // namespace addressinput
69 } // namespace i18n 67 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698