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

Side by Side Diff: base/string_tokenizer.h

Issue 276067: Adding support for Reset in StringTokenizerT and HttpHeadersIterator.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 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 | « no previous file | base/string_tokenizer_unittest.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 BASE_STRING_TOKENIZER_H_ 5 #ifndef BASE_STRING_TOKENIZER_H_
6 #define BASE_STRING_TOKENIZER_H_ 6 #define BASE_STRING_TOKENIZER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 // StringTokenizerT is a simple string tokenizer class. It works like an 10 // StringTokenizerT is a simple string tokenizer class. It works like an
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 token_is_delim_ = true; 134 token_is_delim_ = true;
135 return true; 135 return true;
136 } 136 }
137 // else skip over delim 137 // else skip over delim
138 } 138 }
139 while (token_end_ != end_ && AdvanceOne(&state, *token_end_)) 139 while (token_end_ != end_ && AdvanceOne(&state, *token_end_))
140 ++token_end_; 140 ++token_end_;
141 return true; 141 return true;
142 } 142 }
143 143
144 // Start iterating through tokens from the beginning of the string.
145 void Reset() {
146 token_end_ = start_pos_;
147 }
148
144 // Returns true if token is a delimiter. When the tokenizer is constructed 149 // Returns true if token is a delimiter. When the tokenizer is constructed
145 // with the RETURN_DELIMS option, this method can be used to check if the 150 // with the RETURN_DELIMS option, this method can be used to check if the
146 // returned token is actually a delimiter. 151 // returned token is actually a delimiter.
147 bool token_is_delim() const { return token_is_delim_; } 152 bool token_is_delim() const { return token_is_delim_; }
148 153
149 // If GetNext() returned true, then these methods may be used to read the 154 // If GetNext() returned true, then these methods may be used to read the
150 // value of the token. 155 // value of the token.
151 const_iterator token_begin() const { return token_begin_; } 156 const_iterator token_begin() const { return token_begin_; }
152 const_iterator token_end() const { return token_end_; } 157 const_iterator token_end() const { return token_end_; }
153 str token() const { return str(token_begin_, token_end_); } 158 str token() const { return str(token_begin_, token_end_); }
154 159
155 private: 160 private:
156 void Init(const_iterator string_begin, 161 void Init(const_iterator string_begin,
157 const_iterator string_end, 162 const_iterator string_end,
158 const str& delims) { 163 const str& delims) {
164 start_pos_ = string_begin;
159 token_end_ = string_begin; 165 token_end_ = string_begin;
160 end_ = string_end; 166 end_ = string_end;
161 delims_ = delims; 167 delims_ = delims;
162 options_ = 0; 168 options_ = 0;
163 } 169 }
164 170
165 bool IsDelim(char_type c) const { 171 bool IsDelim(char_type c) const {
166 return delims_.find(c) != str::npos; 172 return delims_.find(c) != str::npos;
167 } 173 }
168 174
(...skipping 19 matching lines...) Expand all
188 state->in_quote = false; 194 state->in_quote = false;
189 } 195 }
190 } else { 196 } else {
191 if (IsDelim(c)) 197 if (IsDelim(c))
192 return false; 198 return false;
193 state->in_quote = IsQuote(state->quote_char = c); 199 state->in_quote = IsQuote(state->quote_char = c);
194 } 200 }
195 return true; 201 return true;
196 } 202 }
197 203
204 const_iterator start_pos_;
198 const_iterator token_begin_; 205 const_iterator token_begin_;
199 const_iterator token_end_; 206 const_iterator token_end_;
200 const_iterator end_; 207 const_iterator end_;
201 str delims_; 208 str delims_;
202 str quotes_; 209 str quotes_;
203 int options_; 210 int options_;
204 bool token_is_delim_; 211 bool token_is_delim_;
205 }; 212 };
206 213
207 typedef StringTokenizerT<std::string, std::string::const_iterator> 214 typedef StringTokenizerT<std::string, std::string::const_iterator>
208 StringTokenizer; 215 StringTokenizer;
209 typedef StringTokenizerT<std::wstring, std::wstring::const_iterator> 216 typedef StringTokenizerT<std::wstring, std::wstring::const_iterator>
210 WStringTokenizer; 217 WStringTokenizer;
211 typedef StringTokenizerT<std::string, const char*> CStringTokenizer; 218 typedef StringTokenizerT<std::string, const char*> CStringTokenizer;
212 219
213 #endif // BASE_STRING_TOKENIZER_H_ 220 #endif // BASE_STRING_TOKENIZER_H_
OLDNEW
« no previous file with comments | « no previous file | base/string_tokenizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698