#include <SString.h>
Collaboration diagram for ACE_Tokenizer:
Public Types | |
enum | { MAX_DELIMITERS = 16, MAX_PRESERVES = 16 } |
Public Member Functions | |
ACE_Tokenizer (ACE_TCHAR *buffer) | |
int | delimiter (ACE_TCHAR d) |
int | delimiter_replace (ACE_TCHAR d, ACE_TCHAR replacement) |
int | preserve_designators (ACE_TCHAR start, ACE_TCHAR stop, int strip=1) |
ACE_TCHAR * | next (void) |
Returns the next token. | |
Protected Member Functions | |
int | is_delimiter (ACE_TCHAR d, int &replace, ACE_TCHAR &r) |
int | is_preserve_designator (ACE_TCHAR start, ACE_TCHAR &stop, int &strip) |
Protected Attributes | |
ACE_TCHAR * | buffer_ |
int | index_ |
Preserve_Entry | preserves_ [MAX_PRESERVES] |
The application can specify MAX_PRESERVES preserve designators. | |
int | preserves_index_ |
Pointer to the next free spot in preserves_. | |
Delimiter_Entry | delimiters_ [MAX_DELIMITERS] |
The tokenizer allows MAX_DELIMITERS number of delimiters. | |
int | delimiter_index_ |
Pointer to the next free space in delimiters_. |
Tokenizes a buffer. Allows application to set delimiters and preserve designators. Does not allow special characters, yet (e.g., printf ("\"like a quoted string\"")).
Definition at line 265 of file SString.h.
|
Definition at line 375 of file SString.h.
00375 { 00376 MAX_DELIMITERS=16, 00377 MAX_PRESERVES=16 00378 }; |
|
buffer will be parsed. Notice that ACE_Tokenizer will modify buffer if you use
Definition at line 337 of file SString.cpp. References ACE_TCHAR.
00338 : buffer_ (buffer), 00339 index_ (0), 00340 preserves_index_ (0), 00341 delimiter_index_ (0) 00342 { 00343 } |
|
d is a delimiter.
This will print out:
Definition at line 346 of file SString.cpp. References ACE_TCHAR, ACE_Tokenizer::Delimiter_Entry::delimiter_, delimiter_index_, delimiters_, MAX_DELIMITERS, and ACE_Tokenizer::Delimiter_Entry::replace_. Referenced by ACE::get_ip_interfaces().
00347 { 00348 if (delimiter_index_ == MAX_DELIMITERS) 00349 return -1; 00350 00351 delimiters_[delimiter_index_].delimiter_ = d; 00352 delimiters_[delimiter_index_].replace_ = 0; 00353 delimiter_index_++; 00354 return 0; 00355 } |
|
d is a delimiter and, when found, will be replaced by replacement.
This will print out:
Definition at line 358 of file SString.cpp. References ACE_TCHAR, ACE_Tokenizer::Delimiter_Entry::delimiter_, delimiter_index_, delimiters_, MAX_DELIMITERS, ACE_Tokenizer::Delimiter_Entry::replace_, and ACE_Tokenizer::Delimiter_Entry::replacement_. Referenced by ACE_Process_Options::command_line_argv(), and ACE_Configuration::expand_path().
00360 { 00361 // Make it possible to replace delimiters on-the-fly, e.g., parse 00362 // string until certain token count and then copy rest of the 00363 // original string. 00364 for (int i = 0; i < delimiter_index_; i++) 00365 if (delimiters_[i].delimiter_ == d) 00366 { 00367 delimiters_[i].replacement_ = replacement; 00368 delimiters_[i].replace_ = 1; 00369 return 0; 00370 } 00371 00372 if (delimiter_index_ >= MAX_DELIMITERS) 00373 return -1; 00374 00375 delimiters_[delimiter_index_].delimiter_ = d; 00376 delimiters_[delimiter_index_].replacement_ = replacement; 00377 delimiters_[delimiter_index_].replace_ = 1; 00378 delimiter_index_++; 00379 return 0; 00380 } |
|
Returns 1 if is a delimiter, 0 otherwise. If should be replaced with , is set to 1, otherwise 0. Definition at line 398 of file SString.cpp. References ACE_TCHAR, ACE_Tokenizer::Delimiter_Entry::delimiter_, delimiter_index_, delimiters_, ACE_Tokenizer::Delimiter_Entry::replace_, and ACE_Tokenizer::Delimiter_Entry::replacement_. Referenced by next().
00401 { 00402 replace = 0; 00403 00404 for (int x = 0; x < delimiter_index_; x++) 00405 if (delimiters_[x].delimiter_ == d) 00406 { 00407 if (delimiters_[x].replace_) 00408 { 00409 r = delimiters_[x].replacement_; 00410 replace = 1; 00411 } 00412 return 1; 00413 } 00414 00415 return 0; 00416 } |
|
If is a start preserve designator, returns 1 and sets to the stop designator. Returns 0 if is not a preserve designator. Definition at line 419 of file SString.cpp. References ACE_TCHAR, preserves_, preserves_index_, ACE_Tokenizer::Preserve_Entry::start_, and ACE_Tokenizer::Preserve_Entry::stop_. Referenced by next().
00422 { 00423 for (int x = 0; x < preserves_index_; x++) 00424 if (preserves_[x].start_ == start) 00425 { 00426 stop = preserves_[x].stop_; 00427 strip = preserves_[x].strip_; 00428 return 1; 00429 } 00430 00431 return 0; 00432 } |
|
Returns the next token.
Definition at line 435 of file SString.cpp. References ACE_TCHAR, is_delimiter(), and is_preserve_designator(). Referenced by ACE_Process_Options::command_line_argv(), ACE_Configuration::expand_path(), and ACE::get_ip_interfaces().
00436 { 00437 // Check if the previous pass was the last one in the buffer. 00438 if (index_ == -1) 00439 { 00440 index_ = 0; 00441 return 0; 00442 } 00443 00444 ACE_TCHAR replacement = 0; 00445 int replace; 00446 ACE_TCHAR *next_token; 00447 00448 // Skip all leading delimiters. 00449 for (;;) 00450 { 00451 // Check for end of string. 00452 if (buffer_[index_] == '\0') 00453 { 00454 // If we hit EOS at the start, return 0. 00455 index_ = 0; 00456 return 0; 00457 } 00458 00459 if (this->is_delimiter (buffer_[index_], 00460 replace, 00461 replacement)) 00462 index_++; 00463 else 00464 break; 00465 } 00466 00467 // When we reach this point, buffer_[index_] is a non-delimiter and 00468 // not EOS - the start of our next_token. 00469 next_token = buffer_ + index_; 00470 00471 // A preserved region is it's own token. 00472 ACE_TCHAR stop; 00473 int strip; 00474 if (this->is_preserve_designator (buffer_[index_], 00475 stop, 00476 strip)) 00477 { 00478 while (++index_) 00479 { 00480 if (buffer_[index_] == '\0') 00481 { 00482 index_ = -1; 00483 goto EXIT_LABEL; 00484 } 00485 00486 if (buffer_[index_] == stop) 00487 break; 00488 } 00489 00490 if (strip) 00491 { 00492 // Skip start preserve designator. 00493 next_token += 1; 00494 // Zap the stop preserve designator. 00495 buffer_[index_] = '\0'; 00496 // Increment to the next token. 00497 index_++; 00498 } 00499 00500 goto EXIT_LABEL; 00501 } 00502 00503 // Step through finding the next delimiter or EOS. 00504 for (;;) 00505 { 00506 // Advance pointer. 00507 index_++; 00508 00509 // Check for delimiter. 00510 if (this->is_delimiter (buffer_[index_], 00511 replace, 00512 replacement)) 00513 { 00514 // Replace the delimiter. 00515 if (replace != 0) 00516 buffer_[index_] = replacement; 00517 00518 // Move the pointer up and return. 00519 index_++; 00520 goto EXIT_LABEL; 00521 } 00522 00523 // A preserve designator signifies the end of this token. 00524 if (this->is_preserve_designator (buffer_[index_], 00525 stop, 00526 strip)) 00527 goto EXIT_LABEL; 00528 00529 // Check for end of string. 00530 if (buffer_[index_] == '\0') 00531 { 00532 index_ = -1; 00533 goto EXIT_LABEL; 00534 } 00535 } 00536 00537 EXIT_LABEL: 00538 return next_token; 00539 } |
|
Extract string between a pair of designator characters. For instance, quotes, or '(' and ')'. start specifies the begin designator. stop specifies the end designator. strip If strip == 1, then the preserve designators will be stripped from the tokens returned by next.
This will print out:
Example with strip = 1:
This will print out:
Definition at line 383 of file SString.cpp. References ACE_TCHAR, MAX_PRESERVES, preserves_, preserves_index_, ACE_Tokenizer::Preserve_Entry::start_, ACE_Tokenizer::Preserve_Entry::stop_, and ACE_Tokenizer::Preserve_Entry::strip_. Referenced by ACE_Process_Options::command_line_argv().
00386 { 00387 if (preserves_index_ == MAX_PRESERVES) 00388 return -1; 00389 00390 preserves_[preserves_index_].start_ = start; 00391 preserves_[preserves_index_].stop_ = stop; 00392 preserves_[preserves_index_].strip_ = strip; 00393 preserves_index_++; 00394 return 0; 00395 } |
|
|
|
Pointer to the next free space in delimiters_.
Definition at line 452 of file SString.h. Referenced by delimiter(), delimiter_replace(), and is_delimiter(). |
|
The tokenizer allows MAX_DELIMITERS number of delimiters.
Definition at line 449 of file SString.h. Referenced by delimiter(), delimiter_replace(), and is_delimiter(). |
|
|
|
The application can specify MAX_PRESERVES preserve designators.
Definition at line 421 of file SString.h. Referenced by is_preserve_designator(), and preserve_designators(). |
|
Pointer to the next free spot in preserves_.
Definition at line 424 of file SString.h. Referenced by is_preserve_designator(), and preserve_designators(). |