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

Side by Side Diff: third_party/libaddressinput/chromium/input_suggester.h

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixup includes and comments for tries and ICU. Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_INPUT_SUGGESTER_H_
6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_INPUT_SUGGESTER_H_
7
8 #include <stdint.h>
9 #include <cstddef>
10 #include <map>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "third_party/icu/source/i18n/unicode/coll.h"
16 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi eld.h"
17 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_in put_helper.h"
18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_va lidator.h"
19 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/region_dat a_builder.h"
20
21 namespace i18n {
22 namespace addressinput {
23 class PreloadSupplier;
24 class RegionData;
25 struct AddressData;
26 }
27 }
28
29 namespace autofill {
30
31 // Suggests address completions for a partially entered address from the user.
32 class InputSuggester {
33 public:
34 // Does not take ownership of |supplier|, which should not be NULL.
35 explicit InputSuggester(::i18n::addressinput::PreloadSupplier* supplier);
36 ~InputSuggester();
37
38 // Fills in |suggestions| for the partially typed in |user_input|, assuming
39 // the user is typing in the |focused_field|. If the number of |suggestions|
40 // is over the |suggestion_limit|, then returns no |suggestions| at all.
41 //
42 // Sample user input 1:
43 // country code = "US"
44 // postal code = "90066"
45 // focused field = POSTAL_CODE
46 // suggestions limit = 1
47 // Suggestion:
48 // [{administrative_area: "CA"}]
49 //
50 // Sample user input 2:
51 // country code = "CN"
52 // dependent locality = "Zongyang"
53 // focused field = DEPENDENT_LOCALITY
54 // suggestions limit = 10
55 // Suggestion:
56 // [{dependent_locality: "Zongyang Xian",
57 // locality: "Anqing Shi",
58 // administrative_area: "Anhui Sheng"}]
59 //
60 // Builds the index for generating suggestions lazily.
61 //
62 // The |suggestions| parameter should not be NULL. The |focused_field|
63 // parameter should be either POSTAL_CODE or between ADMIN_AREA and
64 // DEPENDENT_LOCALITY inclusively.
65 void GetSuggestions(
66 const ::i18n::addressinput::AddressData& user_input,
67 ::i18n::addressinput::AddressField focused_field,
68 size_t suggestion_limit,
69 std::vector< ::i18n::addressinput::AddressData>* suggestions);
70
71 private:
72 class SubRegionData;
73
74 // Canonicalizes strings for case and diacritic insensitive comparison.
75 class StringCanonicalizer {
76 public:
77 // Initializes the canonicalizer. This is slow, so avoid calling it more
78 // often than necessary.
79 StringCanonicalizer();
80 ~StringCanonicalizer();
81
82 // Returns a canonical version of the string that can be used for comparing
83 // strings regardless of diacritics and capitalization.
84 // Canonicalize("Texas") == Canonicalize("T\u00E9xas");
85 // Canonicalize("Texas") == Canonicalize("teXas");
86 // Canonicalize("Texas") != Canonicalize("California");
87 //
88 // The output is not human-readable.
89 // Canonicalize("Texas") != "Texas";
90 //
91 // The caller does not own the result, which will not be NULL. The
92 // |original| parameter should not be empty. The |result_size| parameter
93 // should not be NULL.
94 const uint8_t* Canonicalize(const std::string& original,
95 int32_t* result_size) const;
96
97 private:
98 mutable int32_t buffer_size_;
99 mutable scoped_ptr<uint8_t[]> buffer_;
100 scoped_ptr<icu::Collator> collator_;
101
102 DISALLOW_COPY_AND_ASSIGN(StringCanonicalizer);
103 };
104
105 // The method to be invoked by |validated_| callback.
106 void Validated(bool success,
107 const ::i18n::addressinput::AddressData&,
108 const ::i18n::addressinput::FieldProblemMap&);
109
110 // Data source for region data.
111 ::i18n::addressinput::RegionDataBuilder region_data_builder_;
112
113 // Suggests sub-regions based on postal code.
114 const ::i18n::addressinput::AddressInputHelper input_helper_;
115
116 // Verifies that suggested sub-regions match the postal code.
117 ::i18n::addressinput::AddressValidator validator_;
118
119 // The callback for |validator_| to invoke when validation finishes.
120 const scoped_ptr<const ::i18n::addressinput::AddressValidator::Callback>
121 validated_;
122
123 // A mapping from a COUNTRY level region to a collection of all of its
124 // sub-regions along with metadata used to construct suggestions.
125 std::map<const ::i18n::addressinput::RegionData*, SubRegionData> sub_regions_;
126
127 // Canonicalizes strings for case and diacritic insensitive search of
128 // sub-region names.
129 StringCanonicalizer canonicalizer_;
130
131 DISALLOW_COPY_AND_ASSIGN(InputSuggester);
132 };
133
134 } // namespace autofill
135
136 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_INPUT_SUGGESTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698