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

Side by Side Diff: components/autofill/core/browser/address_rewriter.h

Issue 2137533002: Embed address normalization rewriting rules. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
(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_
OLDNEW
« no previous file with comments | « components/autofill/core/browser/BUILD.gn ('k') | components/autofill/core/browser/address_rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698