OLD | NEW |
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 |
11 // iterator that with each step (see the Advance method) updates members that | 11 // iterator that with each step (see the Advance method) updates members that |
12 // refer to the next token in the input string. The user may optionally | 12 // refer to the next token in the input string. The user may optionally |
13 // configure the tokenizer to return delimiters. | 13 // configure the tokenizer to return delimiters. |
14 // | 14 // |
15 // | 15 // |
16 // EXAMPLE 1: | 16 // EXAMPLE 1: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // label = "option-value"; | 67 // label = "option-value"; |
68 // next_is_value = false; | 68 // next_is_value = false; |
69 // } else { | 69 // } else { |
70 // label = "mime-type"; | 70 // label = "mime-type"; |
71 // } | 71 // } |
72 // printf("%s: %s\n", label, t.token().c_str()); | 72 // printf("%s: %s\n", label, t.token().c_str()); |
73 // } | 73 // } |
74 // } | 74 // } |
75 // | 75 // |
76 // | 76 // |
77 template <class str> | 77 template <class str, class const_iterator> |
78 class StringTokenizerT { | 78 class StringTokenizerT { |
79 public: | 79 public: |
80 typedef typename str::const_iterator const_iterator; | |
81 typedef typename str::value_type char_type; | 80 typedef typename str::value_type char_type; |
82 | 81 |
83 // Options that may be pass to set_options() | 82 // Options that may be pass to set_options() |
84 enum { | 83 enum { |
85 // Specifies the delimiters should be returned as tokens | 84 // Specifies the delimiters should be returned as tokens |
86 RETURN_DELIMS = 1 << 0, | 85 RETURN_DELIMS = 1 << 0, |
87 }; | 86 }; |
88 | 87 |
89 StringTokenizerT(const str& string, | 88 StringTokenizerT(const str& string, |
90 const str& delims) { | 89 const str& delims) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 186 |
188 const_iterator token_begin_; | 187 const_iterator token_begin_; |
189 const_iterator token_end_; | 188 const_iterator token_end_; |
190 const_iterator end_; | 189 const_iterator end_; |
191 str delims_; | 190 str delims_; |
192 str quotes_; | 191 str quotes_; |
193 int options_; | 192 int options_; |
194 bool token_is_delim_; | 193 bool token_is_delim_; |
195 }; | 194 }; |
196 | 195 |
197 typedef StringTokenizerT<std::string> StringTokenizer; | 196 typedef StringTokenizerT<std::string, std::string::const_iterator> |
198 typedef StringTokenizerT<std::wstring> WStringTokenizer; | 197 StringTokenizer; |
| 198 typedef StringTokenizerT<std::wstring, std::wstring::const_iterator> |
| 199 WStringTokenizer; |
| 200 typedef StringTokenizerT<std::string, const char*> CStringTokenizer; |
199 | 201 |
200 #endif // BASE_STRING_TOKENIZER_H__ | 202 #endif // BASE_STRING_TOKENIZER_H_ |
201 | 203 |
OLD | NEW |