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

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

Issue 6877130: These changes *are* for review :) (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ 5 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_
6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ 6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
12 #include "base/string16.h" 13 #include "base/string16.h"
13 #include "chrome/browser/autofill/autofill_type.h" 14 #include "chrome/browser/autofill/autofill_type.h"
14 #include "chrome/browser/autofill/form_group.h" 15 #include "chrome/browser/autofill/form_group.h"
15 16
16 // A form group that stores phone number information. 17 // A form group that stores phone number information.
17 class PhoneNumber : public FormGroup { 18 class PhoneNumber : public FormGroup {
18 public: 19 public:
19 PhoneNumber(); 20 PhoneNumber();
20 explicit PhoneNumber(const PhoneNumber& number); 21 explicit PhoneNumber(AutofillType::FieldTypeGroup phone_group);
22 PhoneNumber(const PhoneNumber& number);
21 virtual ~PhoneNumber(); 23 virtual ~PhoneNumber();
22 24
23 PhoneNumber& operator=(const PhoneNumber& number); 25 PhoneNumber& operator=(const PhoneNumber& number);
24 26
25 // FormGroup implementation: 27 // FormGroup implementation:
26 virtual void GetMatchingTypes(const string16& text, 28 virtual void GetMatchingTypes(const string16& text,
27 FieldTypeSet* matching_types) const; 29 FieldTypeSet* matching_types) const;
28 virtual void GetNonEmptyTypes(FieldTypeSet* non_empty_typess) const; 30 virtual void GetNonEmptyTypes(FieldTypeSet* non_empty_typess) const;
29 virtual string16 GetInfo(AutofillFieldType type) const; 31 virtual string16 GetInfo(AutofillFieldType type) const;
30 virtual void SetInfo(AutofillFieldType type, const string16& value); 32 virtual void SetInfo(AutofillFieldType type, const string16& value);
31 33
32 // Parses |value| to extract the components of a phone number. |number| 34 // Validates |number_| and translates it into digits-only format.
33 // returns the trailing 7 digits, |city_code| returns the next 3 digits, and 35 // Locale must be set.
34 // |country_code| returns any remaining digits. 36 bool NormalizePhone();
35 // Separator characters are stripped before parsing the digits.
36 // Returns true if parsing was successful, false otherwise.
37 static bool ParsePhoneNumber(const string16& value,
38 string16* number,
39 string16* city_code,
40 string16* country_code);
41 37
42 // Size and offset of the prefix and suffix portions of phone numbers. 38 // Size and offset of the prefix and suffix portions of phone numbers.
43 static const int kPrefixOffset = 0; 39 static const int kPrefixOffset = 0;
44 static const int kPrefixLength = 3; 40 static const int kPrefixLength = 3;
45 static const int kSuffixOffset = 3; 41 static const int kSuffixOffset = 3;
46 static const int kSuffixLength = 4; 42 static const int kSuffixLength = 4;
47 43
44 // Sets locale for normalizing phone numbers. Must be called if you get
45 // normalized number or use NormalizePhone() function;
46 // Setting it to "", actually sets it to default locale - "US".
Ilya Sherman 2011/05/14 04:38:51 Should we use the app locale rather than always de
GeorgeY 2011/05/18 17:41:45 It is actually used in one place - NormalizePhones
isherman%chromium.org_gtempaccount.com 2011/05/18 18:06:09 In that case, perhaps we should have a DCHECK here
47 void set_locale(const std::string& locale);
48
48 // The following functions should return the field type for each part of the 49 // The following functions should return the field type for each part of the
49 // phone number. Currently, these are either fax or home phone number types. 50 // phone number. Currently, these are either fax or home phone number types.
50 virtual AutofillFieldType GetNumberType() const = 0; 51 AutofillFieldType GetNumberType() const;
51 virtual AutofillFieldType GetCityCodeType() const = 0; 52 AutofillFieldType GetCityCodeType() const;
52 virtual AutofillFieldType GetCountryCodeType() const = 0; 53 AutofillFieldType GetCountryCodeType() const;
53 virtual AutofillFieldType GetCityAndNumberType() const = 0; 54 AutofillFieldType GetCityAndNumberType() const;
54 virtual AutofillFieldType GetWholeNumberType() const = 0; 55 AutofillFieldType GetWholeNumberType() const;
55 56
56 private: 57 private:
57 FRIEND_TEST_ALL_PREFIXES(PhoneNumberTest, Matcher); 58 FRIEND_TEST_ALL_PREFIXES(PhoneNumberTest, Matcher);
58 59
59 const string16& country_code() const { return country_code_; }
60 const string16& city_code() const { return city_code_; }
61 const string16& number() const { return number_; } 60 const string16& number() const { return number_; }
62 const string16& extension() const { return extension_; } 61 const string16& extension() const { return extension_; }
63 string16 CityAndNumber() const { return city_code_ + number_; }
64 62
65 // Returns the entire phone number as a string, without punctuation.
66 virtual string16 WholeNumber() const;
67
68 void set_country_code(const string16& country_code) {
69 country_code_ = country_code;
70 }
71 void set_city_code(const string16& city_code) { city_code_ = city_code; }
72 void set_number(const string16& number); 63 void set_number(const string16& number);
73 void set_extension(const string16& extension) { extension_ = extension; } 64 void set_extension(const string16& extension) { extension_ = extension; }
74 void set_whole_number(const string16& whole_number);
75 65
76 // The numbers will be digits only (no punctuation), so any call to the IsX() 66 // The numbers will be digits only (no punctuation), so any call to the IsX()
77 // functions should first call StripPunctuation on the text. 67 // functions should first call StripPunctuation on the text.
78 bool IsNumber(const string16& text) const; 68 bool IsNumber(const string16& text, const string16& number) const;
79 bool IsCityCode(const string16& text) const;
80 bool IsCountryCode(const string16& text) const;
81 bool IsCityAndNumber(const string16& text) const;
82 bool IsWholeNumber(const string16& text) const; 69 bool IsWholeNumber(const string16& text) const;
83 70
84 // Verifies that |number| is a valid phone number.
85 bool Validate(const string16& number) const;
86
87 // Removes any punctuation characters from |number|.
88 static void StripPunctuation(string16* number); 71 static void StripPunctuation(string16* number);
89 72
73 // Phone group - currently it is PHONE_HOME and PHONE_FAX.
74 AutofillType::FieldTypeGroup phone_group_;
75 // Locale for phone normalizing.
76 std::string locale_;
90 // The pieces of the phone number. 77 // The pieces of the phone number.
91 string16 country_code_;
92 string16 city_code_; // city or area code.
93 string16 number_; 78 string16 number_;
94 string16 extension_; 79 string16 extension_;
95 }; 80 };
96 81
97 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ 82 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698