OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 ANDROID_WEBVIEW_NATIVE_ADDRESS_PARSER_INTERNAL_H_ | |
6 #define ANDROID_WEBVIEW_NATIVE_ADDRESS_PARSER_INTERNAL_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <vector> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/strings/string_tokenizer.h" | |
14 | |
15 namespace android_webview { | |
16 | |
17 namespace address_parser { | |
18 | |
19 // Internal classes and functions for address parsing. | |
20 namespace internal { | |
21 | |
22 // Exposed for tests. | |
23 struct Word { | |
24 base::string16::const_iterator begin; | |
25 base::string16::const_iterator end; | |
26 | |
27 Word(); | |
28 Word(const base::string16::const_iterator& begin, | |
29 const base::string16::const_iterator& end); | |
30 Word(const Word& other); | |
31 }; | |
32 | |
33 // Exposed for tests. | |
34 class HouseNumberParser { | |
35 public: | |
36 HouseNumberParser(); | |
37 | |
38 bool Parse(const base::string16::const_iterator& begin, | |
39 const base::string16::const_iterator& end, | |
40 Word* word); | |
41 | |
42 private: | |
43 static inline bool IsPreDelimiter(base::char16 character); | |
44 static inline bool IsPostDelimiter(base::char16 character); | |
45 inline void RestartOnNextDelimiter(); | |
46 | |
47 inline bool CheckFinished(Word* word) const; | |
48 inline void AcceptChars(size_t num_chars); | |
49 inline void SkipChars(size_t num_chars); | |
50 inline void ResetState(); | |
51 | |
52 // Iterators to the beginning, current position and ending of the string | |
53 // being currently parsed. | |
54 base::string16::const_iterator begin_; | |
55 base::string16::const_iterator it_; | |
56 base::string16::const_iterator end_; | |
57 | |
58 // Number of digits found in the current result candidate. | |
59 size_t num_digits_; | |
60 | |
61 // Number of characters previous to the current iterator that belong | |
62 // to the current result candidate. | |
63 size_t result_chars_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(HouseNumberParser); | |
66 }; | |
67 | |
68 typedef std::vector<Word> WordList; | |
69 typedef base::StringTokenizerT<base::string16, base::string16::const_iterator> | |
70 String16Tokenizer; | |
71 | |
72 // These are exposed for tests. | |
73 bool FindStateStartingInWord(WordList* words, | |
74 size_t state_first_word, | |
75 size_t* state_last_word, | |
76 String16Tokenizer* tokenizer, | |
77 size_t* state_index); | |
78 | |
79 bool IsValidLocationName(const Word& word); | |
80 bool IsZipValid(const Word& word, size_t state_index); | |
81 bool IsZipValidForState(const Word& word, size_t state_index); | |
82 | |
83 } // namespace internal | |
84 | |
85 } // namespace address_parser | |
86 | |
87 } // namespace android_webview | |
88 | |
89 #endif // ANDROID_WEBVIEW_NATIVE_ADDRESS_PARSER_INTERNAL_H_ | |
OLD | NEW |