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_
10 #include "base/strings/string_tokenizer.h"
11 #include "content/common/content_export.h"
15 namespace address_parser
{
17 // Internal classes and functions for address parsing.
21 struct CONTENT_EXPORT Word
{
22 string16::const_iterator begin
;
23 string16::const_iterator end
;
26 Word(const string16::const_iterator
& begin
,
27 const string16::const_iterator
& end
);
31 class CONTENT_EXPORT HouseNumberParser
{
33 HouseNumberParser() {}
35 bool Parse(const string16::const_iterator
& begin
,
36 const string16::const_iterator
& end
,
40 static inline bool IsPreDelimiter(char16 character
);
41 static inline bool IsPostDelimiter(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 string16::const_iterator begin_
;
52 string16::const_iterator it_
;
53 string16::const_iterator end_
;
55 // Number of digits found in the current result candidate.
58 // Number of characters previous to the current iterator that belong
59 // to the current result candidate.
62 DISALLOW_COPY_AND_ASSIGN(HouseNumberParser
);
65 typedef std::vector
<Word
> WordList
;
66 typedef base::StringTokenizerT
<string16
, string16::const_iterator
>
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
,
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_