Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / common / android / address_parser_internal.h
blob2c9d19cecfe70e3c581fab10514b78eb21b693a4
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.
5 #ifndef CONTENT_COMMON_ADDRESS_PARSER_INTERNAL_H_
6 #define CONTENT_COMMON_ADDRESS_PARSER_INTERNAL_H_
8 #include <vector>
10 #include "base/strings/string_tokenizer.h"
11 #include "content/common/content_export.h"
13 namespace content {
15 namespace address_parser {
17 // Internal classes and functions for address parsing.
18 namespace internal {
20 // Exposed for tests.
21 struct CONTENT_EXPORT Word {
22 base::string16::const_iterator begin;
23 base::string16::const_iterator end;
25 Word() {}
26 Word(const base::string16::const_iterator& begin,
27 const base::string16::const_iterator& end);
30 // Exposed for tests.
31 class CONTENT_EXPORT HouseNumberParser {
32 public:
33 HouseNumberParser() {}
35 bool Parse(const base::string16::const_iterator& begin,
36 const base::string16::const_iterator& end,
37 Word* word);
39 private:
40 static inline bool IsPreDelimiter(base::char16 character);
41 static inline bool IsPostDelimiter(base::char16 character);
42 inline void RestartOnNextDelimiter();
44 inline bool CheckFinished(Word* word) const;
45 inline void AcceptChars(size_t num_chars);
46 inline void SkipChars(size_t num_chars);
47 inline void ResetState();
49 // Iterators to the beginning, current position and ending of the string
50 // being currently parsed.
51 base::string16::const_iterator begin_;
52 base::string16::const_iterator it_;
53 base::string16::const_iterator end_;
55 // Number of digits found in the current result candidate.
56 size_t num_digits_;
58 // Number of characters previous to the current iterator that belong
59 // to the current result candidate.
60 size_t result_chars_;
62 DISALLOW_COPY_AND_ASSIGN(HouseNumberParser);
65 typedef std::vector<Word> WordList;
66 typedef base::StringTokenizerT<base::string16, base::string16::const_iterator>
67 String16Tokenizer;
69 // These are exposed for tests.
70 CONTENT_EXPORT bool FindStateStartingInWord(WordList* words,
71 size_t state_first_word,
72 size_t* state_last_word,
73 String16Tokenizer* tokenizer,
74 size_t* state_index);
76 CONTENT_EXPORT bool IsValidLocationName(const Word& word);
77 CONTENT_EXPORT bool IsZipValid(const Word& word, size_t state_index);
78 CONTENT_EXPORT bool IsZipValidForState(const Word& word, size_t state_index);
80 } // namespace internal
82 } // namespace address_parser
84 } // namespace content
86 #endif // CONTENT_COMMON_ADDRESS_PARSER_INTERNAL_H_