OLD | NEW |
(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 |
OLD | NEW |