#include <SString.h>
Public Types | |
| enum | { MAX_DELIMITERS = 16, MAX_PRESERVES = 16 } |
Public Methods | |
| 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. More... | |
Protected Methods | |
| int | is_delimiter (ACE_TCHAR d, int &replace, ACE_TCHAR &r) |
| Returns 1 if <d> is a delimiter, 0 otherwise. If <d> should be replaced with <r>, <replace> is set to 1, otherwise 0. More... | |
| 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. More... | |
| int | preserves_index_ |
| Pointer to the next free spot in preserves_. More... | |
| Delimiter_Entry | delimiters_ [MAX_DELIMITERS] |
| The tokenizer allows MAX_DELIMITERS number of delimiters. More... | |
| int | delimiter_index_ |
| Pointer to the next free space in delimiters_. More... | |
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 258 of file SString.h.
|
|
Definition at line 368 of file SString.h.
00368 {
00369 MAX_DELIMITERS=16,
00370 MAX_PRESERVES=16
00371 };
|
|
|
buffer will be parsed. Notice that ACE_Tokenizer will modify buffer if you use
Definition at line 21 of file SString.cpp. References ACE_TCHAR.
00022 : buffer_ (buffer), 00023 index_ (0), 00024 preserves_index_ (0), 00025 delimiter_index_ (0) 00026 { 00027 } |
|
|
d is a delimiter.
char buf[30];
ACE_OS::strcpy(buf, "William/Joseph/Hagins");
ACE_Tokenizer tok (buf);
tok.delimiter ('/');
for (char *p = tok.next (); p; p = tok.next ())
cout << p << endl;
This will print out:
William/Joseph/Hagins
Joseph/Hagins
Hagins Definition at line 30 of file SString.cpp. References ACE_TCHAR, delimiter_index_, delimiters_, and MAX_DELIMITERS. Referenced by ACE_Sock_Connect::get_ip_interfaces.
00031 {
00032 if (delimiter_index_ == MAX_DELIMITERS)
00033 return -1;
00034
00035 delimiters_[delimiter_index_].delimiter_ = d;
00036 delimiters_[delimiter_index_].replace_ = 0;
00037 delimiter_index_++;
00038 return 0;
00039 }
|
|
||||||||||||
|
d is a delimiter and, when found, will be replaced by replacement.
char buf[30];
ACE_OS::strcpy(buf, "William/Joseph/Hagins");
ACE_Tokenizer tok (buf);
tok.delimiter_replace ('/', 0);
for (char *p = tok.next (); p; p = tok.next ())
cout << p << endl;
This will print out:
William
Joseph
Hagins Definition at line 42 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.
00044 {
00045 // Make it possible to replace delimiters on-the-fly, e.g., parse
00046 // string until certain token count and then copy rest of the
00047 // original string.
00048 for (int i = 0; i < delimiter_index_; i++)
00049 if (delimiters_[i].delimiter_ == d)
00050 {
00051 delimiters_[i].replacement_ = replacement;
00052 delimiters_[i].replace_ = 1;
00053 return 0;
00054 }
00055
00056 if (delimiter_index_ >= MAX_DELIMITERS)
00057 return -1;
00058
00059 delimiters_[delimiter_index_].delimiter_ = d;
00060 delimiters_[delimiter_index_].replacement_ = replacement;
00061 delimiters_[delimiter_index_].replace_ = 1;
00062 delimiter_index_++;
00063 return 0;
00064 }
|
|
||||||||||||||||
|
Returns 1 if <d> is a delimiter, 0 otherwise. If <d> should be replaced with <r>, <replace> is set to 1, otherwise 0.
Definition at line 82 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.
00085 {
00086 replace = 0;
00087
00088 for (int x = 0; x < delimiter_index_; x++)
00089 if (delimiters_[x].delimiter_ == d)
00090 {
00091 if (delimiters_[x].replace_)
00092 {
00093 r = delimiters_[x].replacement_;
00094 replace = 1;
00095 }
00096 return 1;
00097 }
00098
00099 return 0;
00100 }
|
|
||||||||||||||||
|
If <start> is a start preserve designator, returns 1 and sets <stop> to the stop designator. Returns 0 if <start> is not a preserve designator. Definition at line 103 of file SString.cpp. References ACE_TCHAR, preserves_, preserves_index_, ACE_Tokenizer::Preserve_Entry::start_, ACE_Tokenizer::Preserve_Entry::stop_, and ACE_Tokenizer::Preserve_Entry::strip_. Referenced by next.
00106 {
00107 for (int x = 0; x < preserves_index_; x++)
00108 if (preserves_[x].start_ == start)
00109 {
00110 stop = preserves_[x].stop_;
00111 strip = preserves_[x].strip_;
00112 return 1;
00113 }
00114
00115 return 0;
00116 }
|
|
|
Returns the next token.
Definition at line 119 of file SString.cpp. References ACE_TCHAR, buffer_, index_, is_delimiter, and is_preserve_designator. Referenced by ACE_Process_Options::command_line_argv, ACE_Configuration::expand_path, and ACE_Sock_Connect::get_ip_interfaces.
00120 {
00121 // Check if the previous pass was the last one in the buffer.
00122 if (index_ == -1)
00123 {
00124 index_ = 0;
00125 return 0;
00126 }
00127
00128 ACE_TCHAR replacement;
00129 int replace;
00130 ACE_TCHAR *next_token;
00131
00132 // Skip all leading delimiters.
00133 for (;;)
00134 {
00135 // Check for end of string.
00136 if (buffer_[index_] == '\0')
00137 {
00138 // If we hit EOS at the start, return 0.
00139 index_ = 0;
00140 return 0;
00141 }
00142
00143 if (this->is_delimiter (buffer_[index_],
00144 replace,
00145 replacement))
00146 index_++;
00147 else
00148 break;
00149 }
00150
00151 // When we reach this point, buffer_[index_] is a non-delimiter and
00152 // not EOS - the start of our next_token.
00153 next_token = buffer_ + index_;
00154
00155 // A preserved region is it's own token.
00156 ACE_TCHAR stop;
00157 int strip;
00158 if (this->is_preserve_designator (buffer_[index_],
00159 stop,
00160 strip))
00161 {
00162 while (++index_)
00163 {
00164 if (buffer_[index_] == '\0')
00165 {
00166 index_ = -1;
00167 goto EXIT_LABEL;
00168 }
00169
00170 if (buffer_[index_] == stop)
00171 break;
00172 }
00173
00174 if (strip)
00175 {
00176 // Skip start preserve designator.
00177 next_token += 1;
00178 // Zap the stop preserve designator.
00179 buffer_[index_] = '\0';
00180 // Increment to the next token.
00181 index_++;
00182 }
00183
00184 goto EXIT_LABEL;
00185 }
00186
00187 // Step through finding the next delimiter or EOS.
00188 for (;;)
00189 {
00190 // Advance pointer.
00191 index_++;
00192
00193 // Check for delimiter.
00194 if (this->is_delimiter (buffer_[index_],
00195 replace,
00196 replacement))
00197 {
00198 // Replace the delimiter.
00199 if (replace != 0)
00200 buffer_[index_] = replacement;
00201
00202 // Move the pointer up and return.
00203 index_++;
00204 goto EXIT_LABEL;
00205 }
00206
00207 // A preserve designator signifies the end of this token.
00208 if (this->is_preserve_designator (buffer_[index_],
00209 stop,
00210 strip))
00211 goto EXIT_LABEL;
00212
00213 // Check for end of string.
00214 if (buffer_[index_] == '\0')
00215 {
00216 index_ = -1;
00217 goto EXIT_LABEL;
00218 }
00219 }
00220
00221 EXIT_LABEL:
00222 return next_token;
00223 }
|
|
||||||||||||||||
|
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.
char buf[30];
ACE_OS::strcpy(buf, "William(Joseph)Hagins");
ACE_Tokenizer tok (buf);
tok.preserve_designators ('(', ')', 0);
for (char *p = tok.next (); p; p = tok.next ())
cout << p << endl;
This will print out:
William(Joseph)Hagins
(Joseph)Hagins
)Hagins Example with strip = 1:
char buf[30];
ACE_OS::strcpy(buf, "William(Joseph)Hagins");
ACE_Tokenizer tok (buf);
tok.preserve_designators ('(', ')', 1);
for (char *p = tok.next (); p; p = tok.next ())
cout << p << endl;
This will print out:
William
Joseph
Hagins Definition at line 67 of file SString.cpp. References ACE_TCHAR, MAX_PRESERVES, preserves_, and preserves_index_. Referenced by ACE_Process_Options::command_line_argv.
00070 {
00071 if (preserves_index_ == MAX_PRESERVES)
00072 return -1;
00073
00074 preserves_[preserves_index_].start_ = start;
00075 preserves_[preserves_index_].stop_ = stop;
00076 preserves_[preserves_index_].strip_ = strip;
00077 preserves_index_++;
00078 return 0;
00079 }
|
|
|
Definition at line 385 of file SString.h. Referenced by next. |
|
|
Pointer to the next free space in delimiters_.
Definition at line 445 of file SString.h. Referenced by delimiter, delimiter_replace, and is_delimiter. |
|
|
The tokenizer allows MAX_DELIMITERS number of delimiters.
Definition at line 442 of file SString.h. Referenced by delimiter, delimiter_replace, and is_delimiter. |
|
|
Definition at line 386 of file SString.h. Referenced by next. |
|
|
The application can specify MAX_PRESERVES preserve designators.
Definition at line 414 of file SString.h. Referenced by is_preserve_designator, and preserve_designators. |
|
|
Pointer to the next free spot in preserves_.
Definition at line 417 of file SString.h. Referenced by is_preserve_designator, and preserve_designators. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002