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