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

Unified Diff: chrome/browser/autofill/phone_number_i18n.cc

Issue 6930037: Autofill DOMUI Prefs should work with i18n phone numbers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding DEPS. Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/phone_number_i18n.cc
diff --git a/chrome/browser/autofill/phone_number_i18n.cc b/chrome/browser/autofill/phone_number_i18n.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fc19f2b7f8e069560d350236eca8fdf917b5fbbc
--- /dev/null
+++ b/chrome/browser/autofill/phone_number_i18n.cc
@@ -0,0 +1,36 @@
+// Copyright (c) 2011 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 "chrome/browser/autofill/phone_number_i18n.h"
+
+#include "base/logging.h"
+#include "base/utf_string_conversions.h"
+#include "third_party/libphonenumber/cpp/src/phonenumberutil.h"
+
+using namespace i18n::phonenumbers;
+
+namespace autofill_i18n {
+
+bool PhoneNumbersMatch(const string16& number_a,
+ const string16& number_b,
+ const std::string& country_code) {
+ DCHECK(country_code.size() == 0 || country_code.size() == 2);
+ std::string safe_country_code(country_code);
+ if (safe_country_code.size() == 0)
+ safe_country_code = "US";
+
+ PhoneNumberUtil *phone_util = PhoneNumberUtil::GetInstance();
+ PhoneNumber phone_number_a;
+ phone_util->Parse(UTF16ToUTF8(number_a), safe_country_code, &phone_number_a);
+ PhoneNumber phone_number_b;
+ phone_util->Parse(UTF16ToUTF8(number_b), safe_country_code, &phone_number_b);
+
+ PhoneNumberUtil::MatchType match = phone_util->IsNumberMatch(phone_number_a,
+ phone_number_b);
+ // Allow |NSN_MATCH| for implied country code if one is not set.
+ return match == PhoneNumberUtil::NSN_MATCH ||
+ match == PhoneNumberUtil::EXACT_MATCH;
GeorgeY 2011/05/05 18:24:25 Don't we want to have SHORT_NSN_MATCH here as well
dhollowa 2011/05/05 18:31:01 No, the short match would equate "8002223333" and
+}
+
+} // namespace autofill_i18n

Powered by Google App Engine
This is Rietveld 408576698