OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 210 } |
211 | 211 |
212 bool IsQuote(char_type c) const { | 212 bool IsQuote(char_type c) const { |
213 return quotes_.find(c) != str::npos; | 213 return quotes_.find(c) != str::npos; |
214 } | 214 } |
215 | 215 |
216 struct AdvanceState { | 216 struct AdvanceState { |
217 bool in_quote; | 217 bool in_quote; |
218 bool in_escape; | 218 bool in_escape; |
219 char_type quote_char; | 219 char_type quote_char; |
220 AdvanceState() : in_quote(false), in_escape(false) {} | 220 AdvanceState() : in_quote(false), in_escape(false), quote_char('\0') {} |
221 }; | 221 }; |
222 | 222 |
223 // Returns true if a delimiter was not hit. | 223 // Returns true if a delimiter was not hit. |
224 bool AdvanceOne(AdvanceState* state, char_type c) { | 224 bool AdvanceOne(AdvanceState* state, char_type c) { |
225 if (state->in_quote) { | 225 if (state->in_quote) { |
226 if (state->in_escape) { | 226 if (state->in_escape) { |
227 state->in_escape = false; | 227 state->in_escape = false; |
228 } else if (c == '\\') { | 228 } else if (c == '\\') { |
229 state->in_escape = true; | 229 state->in_escape = true; |
230 } else if (c == state->quote_char) { | 230 } else if (c == state->quote_char) { |
(...skipping 17 matching lines...) Expand all Loading... |
248 bool token_is_delim_; | 248 bool token_is_delim_; |
249 }; | 249 }; |
250 | 250 |
251 typedef StringTokenizerT<std::string, std::string::const_iterator> | 251 typedef StringTokenizerT<std::string, std::string::const_iterator> |
252 StringTokenizer; | 252 StringTokenizer; |
253 typedef StringTokenizerT<std::wstring, std::wstring::const_iterator> | 253 typedef StringTokenizerT<std::wstring, std::wstring::const_iterator> |
254 WStringTokenizer; | 254 WStringTokenizer; |
255 typedef StringTokenizerT<std::string, const char*> CStringTokenizer; | 255 typedef StringTokenizerT<std::string, const char*> CStringTokenizer; |
256 | 256 |
257 #endif // BASE_STRING_TOKENIZER_H_ | 257 #endif // BASE_STRING_TOKENIZER_H_ |
OLD | NEW |