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

Unified 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: Work in progress. 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 side-by-side diff with in-line comments
Download patch
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..e2598a319c469ba2f34d2e999b26bc839ca760e1
--- /dev/null
+++ b/third_party/libaddressinput/chromium/string_compare.cc
@@ -0,0 +1,69 @@
+// 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.
+
+#include "third_party/libaddressinput/src/cpp/src/util/string_compare.h"
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "third_party/icu/source/i18n/unicode/coll.h"
+
+namespace i18n {
+namespace addressinput {
+
+class StringCompare::Impl {
+ public:
+ Impl() {}
+
+ ~Impl() {}
+
+ bool NaturalEquals(const std::string& a, const std::string& b) const {
+ return const_cast<Impl*>(this)->NaturalCompare(a, b) == 0;
roubert 2014/06/24 15:12:55 Is this const_cast<> here to make it possible to c
please use gerrit instead 2014/06/24 21:23:42 Done.
+ }
+
+ bool NaturalLess(const std::string& a, const std::string& b) const {
+ return const_cast<Impl*>(this)->NaturalCompare(a, b) < 0;
+ }
+
+ private:
+ int NaturalCompare(const std::string& a, const std::string& b) {
+ UErrorCode error_code = U_ZERO_ERROR;
+ if (!collator_) {
+ collator_.reset(
+ icu::Collator::createInstance(icu::Locale::getRoot(), error_code));
+ DCHECK(U_SUCCESS(error_code));
+ collator_->setStrength(icu::Collator::PRIMARY);
+ }
+ error_code = U_ZERO_ERROR;
+ int result = collator_->compareUTF8(a, b, error_code);
+ DCHECK(U_SUCCESS(error_code));
+ return result;
+ }
+
+ // ::scoped_ptr is from "base/memory/scoped_ptr.h", which does not interfere
+ // with ::i18n::addressinput::scoped_ptr from
+ // <libaddressinput/util/scoped_ptr.h>.
+ ::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);
+}
+
+bool StringCompare::NaturalLess(const std::string& a,
+ const std::string& b) const {
+ return impl_->NaturalLess(a, b);
+}
+
+} // namespace addressinput
+} // namespace i18n

Powered by Google App Engine
This is Rietveld 408576698