Index: third_party/libaddressinput/chromium/string_compare.cc |
diff --git a/third_party/libaddressinput/chromium/string_compare.cc b/third_party/libaddressinput/chromium/string_compare.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6da832616d429c9b90ca33c42b7a8cc87c7bdaa4 |
--- /dev/null |
+++ b/third_party/libaddressinput/chromium/string_compare.cc |
@@ -0,0 +1,57 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Use "base/memory/scoped_ptr.h" instead. |
+#define I18N_ADDRESSINPUT_UTIL_SCOPED_PTR_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/logging.h" |
+// Must be before string_compare.h to be used in the StringCompare class. |
+#include "base/memory/scoped_ptr.h" |
+#include "third_party/icu/source/common/unicode/errorcode.h" |
+#include "third_party/icu/source/common/unicode/locid.h" |
+#include "third_party/icu/source/common/unicode/unistr.h" |
+#include "third_party/icu/source/common/unicode/utypes.h" |
+#include "third_party/icu/source/i18n/unicode/coll.h" |
+#include "third_party/libaddressinput/src/cpp/src/util/string_compare.h" |
+ |
+namespace i18n { |
+namespace addressinput { |
+ |
+class StringCompare::Impl { |
+ public: |
+ Impl() { |
+ UErrorCode error_code = U_ZERO_ERROR; |
+ collator_.reset(icu::Collator::createInstance( |
+ icu::Locale::getRoot(), error_code)); |
+ DCHECK(U_SUCCESS(error_code)); |
+ collator_->setStrength(icu::Collator::PRIMARY); |
+ } |
+ |
+ ~Impl() {} |
+ |
+ bool NaturalEquals(const std::string& a, const std::string& b) const { |
+ UErrorCode error_code = U_ZERO_ERROR; |
+ bool equal = collator_->compareUTF8(a, b, error_code) == 0; |
+ DCHECK(U_SUCCESS(error_code)); |
+ return equal; |
+ } |
+ |
+ private: |
+ scoped_ptr<icu::Collator> collator_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Impl); |
+}; |
+ |
+StringCompare::StringCompare() : impl_(new Impl) {} |
+ |
+StringCompare::~StringCompare() {} |
+ |
+bool StringCompare::NaturalEquals(const std::string& a, |
+ const std::string& b) const { |
+ return impl_->NaturalEquals(a, b); |
+} |
+ |
+} // namespace addressinput |
+} // namespace i18n |