| 283 | } |
| 284 | |
| 285 | HRWSimpleTokenizer::HRWSimpleTokenizer(const std::string &original_line) |
| 286 | { |
| 287 | std::string line = original_line; |
| 288 | ParserState state = PARSER_DEFAULT; |
| 289 | bool extracting_token = false; |
| 290 | off_t cur_token_start = 0; |
| 291 | size_t cur_token_length = 0; |
| 292 | |
| 293 | for (size_t i = 0; i < line.size(); ++i) { |
| 294 | extracting_token = true; |
| 295 | switch (state) { |
| 296 | case PARSER_DEFAULT: |
| 297 | if ((line[i] == '{') || (line[i] == '<')) { |
| 298 | if (line[i - 1] == '%') { |
| 299 | // pickup what we currently have |
| 300 | cur_token_length = i - cur_token_start - 1; |
| 301 | if (cur_token_length > 0) { |
| 302 | _tokens.push_back(line.substr(cur_token_start, cur_token_length)); |
| 303 | } |
| 304 | |
| 305 | cur_token_start = i - 1; |
| 306 | state = PARSER_IN_EXPANSION; |
| 307 | extracting_token = false; |
| 308 | } |
| 309 | } |
| 310 | break; |
| 311 | case PARSER_IN_EXPANSION: |
| 312 | if ((line[i] == '}') || (line[i] == '>')) { |
| 313 | cur_token_length = i - cur_token_start + 1; |
| 314 | if (cur_token_length > 0) { |
| 315 | _tokens.push_back(line.substr(cur_token_start, cur_token_length)); |
| 316 | } |
| 317 | cur_token_start = i + 1; |
| 318 | state = PARSER_DEFAULT; |
| 319 | extracting_token = false; |
| 320 | } |
| 321 | break; |
| 322 | default: |
| 323 | break; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // take what was left behind |
| 328 | if (extracting_token) { |
| 329 | _tokens.push_back(line.substr(cur_token_start)); |
| 330 | } |
| 331 | } |