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

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

Issue 6935033: Autofill DOMUI Prefs should work with i18n phone numbers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Namespace and comments. Created 9 years, 7 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
« no previous file with comments | « chrome/browser/autofill/phone_number_i18n.h ('k') | chrome/browser/autofill/phone_number_i18n_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8966d00a8dd77676cebe90175ac1529d2a69110d
--- /dev/null
+++ b/chrome/browser/autofill/phone_number_i18n.cc
@@ -0,0 +1,37 @@
+// 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 i18n::phonenumbers::PhoneNumber;
+using i18n::phonenumbers::PhoneNumberUtil;
+
+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;
+}
+
+} // namespace autofill_i18n
« no previous file with comments | « chrome/browser/autofill/phone_number_i18n.h ('k') | chrome/browser/autofill/phone_number_i18n_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698