#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 271 of file SString.h.
|
|
Definition at line 381 of file SString.h.
00381 {
00382 MAX_DELIMITERS=16,
00383 MAX_PRESERVES=16
00384 };
|
|
|
buffer will be parsed. Notice that ACE_Tokenizer will modify buffer if you use
Definition at line 339 of file SString.cpp. References ACE_TCHAR.
00340 : buffer_ (buffer), 00341 index_ (0), 00342 preserves_index_ (0), 00343 delimiter_index_ (0) 00344 { 00345 } |
|
|
d is a delimiter.
This will print out:
Definition at line 348 of file SString.cpp. References ACE_TCHAR, ACE_Tokenizer::Delimiter_Entry::delimiter_, delimiter_index_, delimiters_, MAX_DELIMITERS, and ACE_Tokenizer::Delimiter_Entry::replace_.
00349 {
00350 if (delimiter_index_ == MAX_DELIMITERS)
00351 return -1;
00352
00353 delimiters_[delimiter_index_].delimiter_ = d;
00354 delimiters_[delimiter_index_].replace_ = 0;
00355 delimiter_index_++;
00356 return 0;
00357 }
|
|
||||||||||||
|
d is a delimiter and, when found, will be replaced by replacement.
This will print out:
Definition at line 360 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(), ACE_Configuration::expand_path(), and ACE_Configuration_Win32Registry::resolve_key().
00362 {
00363 // Make it possible to replace delimiters on-the-fly, e.g., parse
00364 // string until certain token count and then copy rest of the
00365 // original string.
00366 for (int i = 0; i < delimiter_index_; i++)
00367 if (delimiters_[i].delimiter_ == d)
00368 {
00369 delimiters_[i].replacement_ = replacement;
00370 delimiters_[i].replace_ = 1;
00371 return 0;
00372 }
00373
00374 if (delimiter_index_ >= MAX_DELIMITERS)
00375 return -1;
00376
00377 delimiters_[delimiter_index_].delimiter_ = d;
00378 delimiters_[delimiter_index_].replacement_ = replacement;
00379 delimiters_[delimiter_index_].replace_ = 1;
00380 delimiter_index_++;
00381 return 0;
00382 }
|
|
||||||||||||||||
|
Returns 1 if is a delimiter, 0 otherwise. If should be replaced with r, is set to 1, otherwise 0. Definition at line 400 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().
00403 {
00404 replace = 0;
00405
00406 for (int x = 0; x < delimiter_index_; x++)
00407 if (delimiters_[x].delimiter_ == d)
00408 {
00409 if (delimiters_[x].replace_)
00410 {
00411 r = delimiters_[x].replacement_;
00412 replace = 1;
00413 }
00414 return 1;
00415 }
00416
00417 return 0;
00418 }
|
|
||||||||||||||||
|
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 421 of file SString.cpp. References ACE_TCHAR, preserves_, preserves_index_, ACE_Tokenizer::Preserve_Entry::start_, and ACE_Tokenizer::Preserve_Entry::stop_. Referenced by next().
00424 {
00425 for (int x = 0; x < preserves_index_; x++)
00426 if (preserves_[x].start_ == start)
00427 {
00428 stop = preserves_[x].stop_;
00429 strip = preserves_[x].strip_;
00430 return 1;
00431 }
00432
00433 return 0;
00434 }
|
|
|
Returns the next token.
Definition at line 437 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_Configuration_Win32Registry::resolve_key().
00438 {
00439 // Check if the previous pass was the last one in the buffer.
00440 if (index_ == -1)
00441 {
00442 index_ = 0;
00443 return 0;
00444 }
00445
00446 ACE_TCHAR replacement = 0;
00447 int replace;
00448 ACE_TCHAR *next_token;
00449
00450 // Skip all leading delimiters.
00451 for (;;)
00452 {
00453 // Check for end of string.
00454 if (buffer_[index_] == '\0')
00455 {
00456 // If we hit EOS at the start, return 0.
00457 index_ = 0;
00458 return 0;
00459 }
00460
00461 if (this->is_delimiter (buffer_[index_],
00462 replace,
00463 replacement))
00464 index_++;
00465 else
00466 break;
00467 }
00468
00469 // When we reach this point, buffer_[index_] is a non-delimiter and
00470 // not EOS - the start of our next_token.
00471 next_token = buffer_ + index_;
00472
00473 // A preserved region is it's own token.
00474 ACE_TCHAR stop;
00475 int strip;
00476 if (this->is_preserve_designator (buffer_[index_],
00477 stop,
00478 strip))
00479 {
00480 while (++index_)
00481 {
00482 if (buffer_[index_] == '\0')
00483 {
00484 index_ = -1;
00485 goto EXIT_LABEL;
00486 }
00487
00488 if (buffer_[index_] == stop)
00489 break;
00490 }
00491
00492 if (strip)
00493 {
00494 // Skip start preserve designator.
00495 next_token += 1;
00496 // Zap the stop preserve designator.
00497 buffer_[index_] = '\0';
00498 // Increment to the next token.
00499 index_++;
00500 }
00501
00502 goto EXIT_LABEL;
00503 }
00504
00505 // Step through finding the next delimiter or EOS.
00506 for (;;)
00507 {
00508 // Advance pointer.
00509 index_++;
00510
00511 // Check for delimiter.
00512 if (this->is_delimiter (buffer_[index_],
00513 replace,
00514 replacement))
00515 {
00516 // Replace the delimiter.
00517 if (replace != 0)
00518 buffer_[index_] = replacement;
00519
00520 // Move the pointer up and return.
00521 index_++;
00522 goto EXIT_LABEL;
00523 }
00524
00525 // A preserve designator signifies the end of this token.
00526 if (this->is_preserve_designator (buffer_[index_],
00527 stop,
00528 strip))
00529 goto EXIT_LABEL;
00530
00531 // Check for end of string.
00532 if (buffer_[index_] == '\0')
00533 {
00534 index_ = -1;
00535 goto EXIT_LABEL;
00536 }
00537 }
00538
00539 EXIT_LABEL:
00540 return next_token;
00541 }
|
|
||||||||||||||||
|
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 385 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().
00388 {
00389 if (preserves_index_ == MAX_PRESERVES)
00390 return -1;
00391
00392 preserves_[preserves_index_].start_ = start;
00393 preserves_[preserves_index_].stop_ = stop;
00394 preserves_[preserves_index_].strip_ = strip;
00395 preserves_index_++;
00396 return 0;
00397 }
|
|
|
|
|
|
Pointer to the next free space in delimiters_.
Definition at line 458 of file SString.h. Referenced by delimiter(), delimiter_replace(), and is_delimiter(). |
|
|
The tokenizer allows MAX_DELIMITERS number of delimiters.
Definition at line 455 of file SString.h. Referenced by delimiter(), delimiter_replace(), and is_delimiter(). |
|
|
|
|
|
The application can specify MAX_PRESERVES preserve designators.
Definition at line 427 of file SString.h. Referenced by is_preserve_designator(), and preserve_designators(). |
|
|
Pointer to the next free spot in preserves_.
Definition at line 430 of file SString.h. Referenced by is_preserve_designator(), and preserve_designators(). |
1.3.6