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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #include "chrome/browser/autofill/phone_number_i18n.h"
6
7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h"
9 #include "third_party/libphonenumber/cpp/src/phonenumberutil.h"
10
11 using i18n::phonenumbers::PhoneNumber;
12 using i18n::phonenumbers::PhoneNumberUtil;
13
14 namespace autofill_i18n {
15
16 bool PhoneNumbersMatch(const string16& number_a,
17 const string16& number_b,
18 const std::string& country_code) {
19 DCHECK(country_code.size() == 0 || country_code.size() == 2);
20 std::string safe_country_code(country_code);
21 if (safe_country_code.size() == 0)
22 safe_country_code = "US";
23
24 PhoneNumberUtil *phone_util = PhoneNumberUtil::GetInstance();
25 PhoneNumber phone_number_a;
26 phone_util->Parse(UTF16ToUTF8(number_a), safe_country_code, &phone_number_a);
27 PhoneNumber phone_number_b;
28 phone_util->Parse(UTF16ToUTF8(number_b), safe_country_code, &phone_number_b);
29
30 PhoneNumberUtil::MatchType match = phone_util->IsNumberMatch(phone_number_a,
31 phone_number_b);
32 // Allow |NSN_MATCH| for implied country code if one is not set.
33 return match == PhoneNumberUtil::NSN_MATCH ||
34 match == PhoneNumberUtil::EXACT_MATCH;
35 }
36
37 } // namespace autofill_i18n
OLDNEW
« 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