OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_ADDRESS_REWRITER_H_ |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_REWRITER_H_ |
| 7 |
| 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/string_piece.h" |
| 10 #include "base/strings/string_util.h" |
| 11 |
| 12 namespace autofill { |
| 13 |
| 14 // A class to apply address normalization rewriting rules to strings. This |
| 15 // class is a wrapper to a handle for a set of cached rules. As such, it is |
| 16 // copyable, movable, and passable by value. |
| 17 class AddressRewriter { |
| 18 public: |
| 19 // Get an AddressRewrite instance which applies the rules for |country_code|. |
| 20 static AddressRewriter ForCountryCode(const base::string16& country_code); |
| 21 |
| 22 // Apply the rewrite rules to |text| and return the result. |
| 23 base::string16 Rewrite(const base::string16& text) const; |
| 24 |
| 25 private: |
| 26 // A handle to the internal rewrite rules this instance is using. |
| 27 const void* impl_ = nullptr; |
| 28 }; |
| 29 |
| 30 // Implementation details follow. Not part of the public interface. |
| 31 namespace internal { |
| 32 |
| 33 // The structure used to statically define a rule. |
| 34 struct Rule { |
| 35 const char* pattern; |
| 36 const char* rewrite; |
| 37 }; |
| 38 |
| 39 // The structure used to statically define a set of rules for a region. |
| 40 struct RegionInfo { |
| 41 const char* region; |
| 42 const Rule* rules; |
| 43 size_t num_rules; |
| 44 |
| 45 bool operator<(const base::StringPiece& region) const { |
| 46 return base::CompareCaseInsensitiveASCII(this->region, region) < 0; |
| 47 } |
| 48 |
| 49 bool operator==(const base::StringPiece& region) const { |
| 50 return base::EqualsCaseInsensitiveASCII(this->region, region); |
| 51 } |
| 52 }; |
| 53 |
| 54 // The statically defined rule table, sorted by region. |
| 55 extern const internal::RegionInfo kRuleTable[]; |
| 56 |
| 57 // The size (in records) of the statically defined rule table. |
| 58 extern const size_t kRuleTableSize; |
| 59 |
| 60 } // namespace internal |
| 61 |
| 62 } // namespace autofill |
| 63 |
| 64 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_REWRITER_H_ |
OLD | NEW |