Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: content/renderer/android/address_detector.h

Issue 10456007: [Android] Split the address parser from AddressDetector for WebView use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: transforming AddressParser into a namespace. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/android/address_detector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_RENDERER_ANDROID_ADDRESS_DETECTOR_H_ 5 #ifndef CONTENT_RENDERER_ANDROID_ADDRESS_DETECTOR_H_
6 #define CONTENT_RENDERER_ANDROID_ADDRESS_DETECTOR_H_ 6 #define CONTENT_RENDERER_ANDROID_ADDRESS_DETECTOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector>
10
11 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
12 #include "base/string_tokenizer.h"
13 #include "content/renderer/android/content_detector.h" 10 #include "content/renderer/android/content_detector.h"
14 11 #include "googleurl/src/gurl.h"
15 class AddressDetectorTest;
16 12
17 namespace content { 13 namespace content {
18 14
19 // Finds a geographical address (currently US only) in the given text string. 15 // Finds a geographical address (currently US only) in the given text string.
20 class AddressDetector : public ContentDetector { 16 class AddressDetector : public ContentDetector {
21 public: 17 public:
22 AddressDetector(); 18 AddressDetector();
23 virtual ~AddressDetector(); 19 virtual ~AddressDetector();
24 20
25 private: 21 private:
26 friend class ::AddressDetectorTest;
27
28 // Implementation of ContentDetector. 22 // Implementation of ContentDetector.
29 virtual bool FindContent(const string16::const_iterator& begin, 23 virtual bool FindContent(const string16::const_iterator& begin,
30 const string16::const_iterator& end, 24 const string16::const_iterator& end,
31 size_t* start_pos, 25 size_t* start_pos,
32 size_t* end_pos, 26 size_t* end_pos,
33 std::string* content_text) OVERRIDE; 27 std::string* content_text) OVERRIDE;
34 virtual GURL GetIntentURL(const std::string& content_text) OVERRIDE; 28 virtual GURL GetIntentURL(const std::string& content_text) OVERRIDE;
35 virtual size_t GetMaximumContentLength() OVERRIDE; 29 virtual size_t GetMaximumContentLength() OVERRIDE;
36 30
37 std::string GetContentText(const string16& text); 31 std::string GetContentText(const string16& text);
38 32
39 // Internal structs and classes. Required to be visible by the unit tests.
40 struct Word {
41 string16::const_iterator begin;
42 string16::const_iterator end;
43
44 Word() {}
45 Word(const string16::const_iterator& begin,
46 const string16::const_iterator& end);
47 };
48
49 class HouseNumberParser {
50 public:
51 HouseNumberParser() {}
52
53 bool Parse(const string16::const_iterator& begin,
54 const string16::const_iterator& end,
55 Word* word);
56
57 private:
58 static inline bool IsPreDelimiter(char16 character);
59 static inline bool IsPostDelimiter(char16 character);
60 inline void RestartOnNextDelimiter();
61
62 inline bool CheckFinished(Word* word) const;
63 inline void AcceptChars(size_t num_chars);
64 inline void SkipChars(size_t num_chars);
65 inline void ResetState();
66
67 // Iterators to the beginning, current position and ending of the string
68 // being currently parsed.
69 string16::const_iterator begin_;
70 string16::const_iterator it_;
71 string16::const_iterator end_;
72
73 // Number of digits found in the current result candidate.
74 size_t num_digits_;
75
76 // Number of characters previous to the current iterator that belong
77 // to the current result candidate.
78 size_t result_chars_;
79
80 DISALLOW_COPY_AND_ASSIGN(HouseNumberParser);
81 };
82
83 typedef std::vector<Word> WordList;
84 typedef StringTokenizerT<string16, string16::const_iterator>
85 String16Tokenizer;
86
87 static bool FindStateStartingInWord(WordList* words,
88 size_t state_first_word,
89 size_t* state_last_word,
90 String16Tokenizer* tokenizer,
91 size_t* state_index);
92
93 static bool IsValidLocationName(const Word& word);
94 static bool IsZipValid(const Word& word, size_t state_index);
95 static bool IsZipValidForState(const Word& word, size_t state_index);
96
97 DISALLOW_COPY_AND_ASSIGN(AddressDetector); 33 DISALLOW_COPY_AND_ASSIGN(AddressDetector);
98 }; 34 };
99 35
100 } // namespace content 36 } // namespace content
101 37
102 #endif // CONTENT_RENDERER_ANDROID_ADDRESS_DETECTOR_H_ 38 #endif // CONTENT_RENDERER_ANDROID_ADDRESS_DETECTOR_H_
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/android/address_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698