1 // Copyright 2019 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 COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_MODEL_DATA_MODEL_UTILS_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_MODEL_DATA_MODEL_UTILS_H_
7 
8 #include <string>
9 
10 #include "base/strings/string16.h"
11 
12 namespace autofill {
13 
14 namespace data_util {
15 
16 // Converts the integer |expiration_month| to base::string16. Returns a value
17 // between ["01"-"12"].
18 base::string16 Expiration2DigitMonthAsString(int expiration_month);
19 
20 // Converts the integer |expiration_year| to base::string16. Returns a value
21 // between ["00"-"99"].
22 base::string16 Expiration2DigitYearAsString(int expiration_year);
23 
24 // Converts the integer |expiration_year| to base::string16.
25 base::string16 Expiration4DigitYearAsString(int expiration_year);
26 
27 // Converts a string representation of a month (such as "February" or "feb."
28 // or "2") into a numeric value in [1, 12]. Returns true on successful
29 // conversion or false if a month was not recognized. When conversion fails,
30 // |expiration_month| is not modified.
31 bool ParseExpirationMonth(const base::string16& text,
32                           const std::string& app_locale,
33                           int* expiration_month);
34 
35 // Parses the |text| and stores the corresponding int value result in
36 // |*expiration_year|. This function accepts two digit years as well as
37 // four digit years between 2000 and 2999. Returns true on success.
38 // On failure, no change is made to |*expiration_year|.
39 bool ParseExpirationYear(const base::string16& text, int* expiration_year);
40 
41 // Sets |*expiration_month| to |value| if |value| is a valid month (1-12).
42 // Returns if any change is made to |*expiration_month|.
43 bool SetExpirationMonth(int value, int* expiration_month);
44 
45 // Sets |*expiration_year| to |value| if |value| is a valid year. See comments
46 // in the function body for the definition of "valid". Returns if any change is
47 // made to |*expiration_year|.
48 bool SetExpirationYear(int value, int* expiration_year);
49 
50 // Finds possible country code in |text| by fetching the first sub-group when
51 // matched with |kAugmentedPhoneCountryCodeRe| regex.
52 base::string16 FindPossiblePhoneCountryCode(const base::string16& text);
53 
54 }  // namespace data_util
55 
56 }  // namespace autofill
57 
58 #endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_MODEL_DATA_MODEL_UTILS_H_
59