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