| 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
|
|
|