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

Side by Side Diff: chrome/browser/autofill/phone_number_i18n.h

Issue 12434004: Move remaining Autofill code to //components/autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix long lines Created 7 years, 9 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
« no previous file with comments | « chrome/browser/autofill/phone_number.cc ('k') | chrome/browser/autofill/phone_number_i18n.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_
6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/string16.h"
14
15 namespace i18n {
16 namespace phonenumbers {
17 class PhoneNumber;
18 }
19 }
20
21 // Utilities to process, normalize and compare international phone numbers.
22 namespace autofill_i18n {
23
24 // Most of the following functions require |region| to operate. The |region| is
25 // a ISO 3166 standard code ("US" for USA, "CZ" for Czech Republic, etc.).
26
27 // Parses the number stored in |value| as a phone number interpreted in the
28 // given |region|, and stores the results into the remaining arguments. The
29 // |region| should be a 2-letter country code. This is an internal function,
30 // exposed in the header file so that it can be tested.
31 bool ParsePhoneNumber(
32 const string16& value,
33 const std::string& region,
34 string16* country_code,
35 string16* city_code,
36 string16* number,
37 i18n::phonenumbers::PhoneNumber* i18n_number) WARN_UNUSED_RESULT;
38
39 // Normalizes phone number, by changing digits in the extended fonts
40 // (such as \xFF1x) into '0'-'9'. Also strips out non-digit characters.
41 string16 NormalizePhoneNumber(const string16& value,
42 const std::string& region);
43
44 // Constructs whole phone number from parts.
45 // |city_code| - area code, could be empty.
46 // |country_code| - country code, could be empty.
47 // |number| - local number, should not be empty.
48 // |region| - current region, the parsing is based on.
49 // |whole_number| - constructed whole number.
50 // Separator characters are stripped before parsing the digits.
51 // Returns true if parsing was successful, false otherwise.
52 bool ConstructPhoneNumber(const string16& country_code,
53 const string16& city_code,
54 const string16& number,
55 const std::string& region,
56 string16* whole_number) WARN_UNUSED_RESULT;
57
58 // Returns true if |number_a| and |number_b| parse to the same phone number in
59 // the given |region|.
60 bool PhoneNumbersMatch(const string16& number_a,
61 const string16& number_b,
62 const std::string& region);
63
64 // The cached phone number, does parsing only once, improves performance.
65 class PhoneObject {
66 public:
67 PhoneObject(const string16& number, const std::string& region);
68 PhoneObject(const PhoneObject&);
69 PhoneObject();
70 ~PhoneObject();
71
72 std::string region() const { return region_; }
73
74 string16 country_code() const { return country_code_; }
75 string16 city_code() const { return city_code_; }
76 string16 number() const { return number_; }
77
78 string16 GetFormattedNumber() const;
79 string16 GetWholeNumber() const;
80
81 PhoneObject& operator=(const PhoneObject& other);
82
83 bool IsValidNumber() const { return i18n_number_ != NULL; }
84
85 private:
86 // The region code used to parse this number.
87 std::string region_;
88
89 // The parsed number and its components.
90 scoped_ptr<i18n::phonenumbers::PhoneNumber> i18n_number_;
91 string16 city_code_;
92 string16 country_code_;
93 string16 number_;
94
95 // Pretty printed version of the whole number, or empty if parsing failed.
96 // Set on first request.
97 mutable string16 formatted_number_;
98
99 // The whole number, normalized to contain only digits if possible.
100 // Set on first request.
101 mutable string16 whole_number_;
102 };
103
104 } // namespace autofill_i18n
105
106 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_
OLDNEW
« no previous file with comments | « chrome/browser/autofill/phone_number.cc ('k') | chrome/browser/autofill/phone_number_i18n.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698