3 //=============================================================================
7 * @author Douglas C. Schmidt (d.schmidt@vanderbilt.edu)
8 * @author Nanbor Wang <nanbor@cs.wustl.edu>
10 //=============================================================================
12 #ifndef ACE_TOKENIZER_T_H
13 #define ACE_TOKENIZER_T_H
15 #include /**/ "ace/pre.h"
17 #include "ace/Global_Macros.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
26 * @class ACE_Tokenizer_T
30 * Tokenizes a buffer. Allows application to set delimiters and
31 * preserve designators. Does not allow special characters, yet
32 * (e.g., printf ("\"like a quoted string\"")).
34 template <class ACE_CHAR_T
>
39 * \a buffer will be parsed. Notice that ACE_Tokenizer_T will modify
40 * \a buffer if you use <code> delimiter_replace </code> or <code>
41 * preserve_designators </code> to do character substitution.
42 * @note You should NOT pass a constant string or string literal
43 * to this constructor, since ACE_Tokenizer_T will try to modify
45 * \sa preserve_designators
46 * \sa preserve_designators
48 ACE_Tokenizer_T (ACE_CHAR_T
*buffer
);
51 * \a d is a delimiter.
52 * \return Returns 0 on success, -1 if there is no memory left.
57 ACE_OS::strcpy(buf, "William/Joseph/Hagins");
59 ACE_Tokenizer_T tok (buf);
61 for (char *p = tok.next (); p; p = tok.next ())
65 * This will print out:
71 int delimiter (ACE_CHAR_T d
);
74 * \a d is a delimiter and, when found, will be replaced by
76 * \return 0 on success, -1 if there is no memory left.
81 ACE_OS::strcpy(buf, "William/Joseph/Hagins");
83 ACE_Tokenizer tok (buf);
84 tok.delimiter_replace ('/', 0);
85 for (char *p = tok.next (); p; p = tok.next ())
89 * This will print out:
95 int delimiter_replace (ACE_CHAR_T d
, ACE_CHAR_T replacement
);
98 * Extract string between a pair of designator characters.
99 * For instance, quotes, or '(' and ')'.
100 * \a start specifies the begin designator.
101 * \a stop specifies the end designator.
102 * \a strip If \a strip == 1, then the preserve
103 * designators will be stripped from the tokens returned by next.
104 * \return 0 on success, -1 if there is no memory left.
106 * <B>Example with strip = 0:</B>
109 ACE_OS::strcpy(buf, "William(Joseph)Hagins");
111 ACE_Tokenizer tok (buf);
112 tok.preserve_designators ('(', ')', 0);
113 for (char *p = tok.next (); p; p = tok.next ())
117 * This will print out:
119 William(Joseph)Hagins
123 * <B>Example with strip = 1:</B>
126 ACE_OS::strcpy(buf, "William(Joseph)Hagins");
128 ACE_Tokenizer tok (buf);
129 tok.preserve_designators ('(', ')', 1);
130 for (char *p = tok.next (); p; p = tok.next ())
134 * This will print out:
140 int preserve_designators (ACE_CHAR_T start
, ACE_CHAR_T stop
, int strip
=1);
142 /// Returns the next token.
143 ACE_CHAR_T
*next (void);
151 /// Returns 1 if @a d is a delimiter, 0 otherwise. If @a d should be
152 /// replaced with @a r, @a replace is set to 1, otherwise 0.
153 int is_delimiter (ACE_CHAR_T d
, int &replace
, ACE_CHAR_T
&r
);
156 * If @a start is a start preserve designator, returns 1 and sets
157 * @a stop to the stop designator. Returns 0 if @a start is not a
158 * preserve designator.
160 int is_preserve_designator (ACE_CHAR_T start
, ACE_CHAR_T
&stop
, int &strip
);
166 * @class Preserve_Entry
168 * @brief Preserve Entry
170 * Defines a set of characters that designate an area that
171 * should not be parsed, but should be treated as a complete
172 * token. For instance, in: (this is a preserve region), start
173 * would be a left paren -(- and stop would be a right paren
174 * -)-. The strip determines whether the designators should be
175 * removed from the token.
183 * Whether the designators should be removed from the token.
190 /// The application can specify MAX_PRESERVES preserve designators.
191 Preserve_Entry preserves_
[MAX_PRESERVES
];
193 /// Pointer to the next free spot in preserves_.
194 int preserves_index_
;
197 * @class Delimiter_Entry
199 * @brief Delimiter Entry
201 * Describes a delimiter for the tokenizer.
203 class Delimiter_Entry
207 * Most commonly a space ' '.
208 * What occurrences of delimiter_ should be replaced with.
209 * Whether replacement_ should be used. This should be replaced
210 * with a technique that sets replacement_ = delimiter by
211 * default. I'll do that next iteration.
213 ACE_CHAR_T delimiter_
;
214 ACE_CHAR_T replacement_
;
218 /// The tokenizer allows MAX_DELIMITERS number of delimiters.
219 Delimiter_Entry delimiters_
[MAX_DELIMITERS
];
221 /// Pointer to the next free space in delimiters_.
222 int delimiter_index_
;
225 typedef ACE_Tokenizer_T
<ACE_TCHAR
> ACE_Tokenizer
;
227 ACE_END_VERSIONED_NAMESPACE_DECL
229 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
230 #include "ace/Tokenizer_T.cpp"
231 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
233 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
234 #pragma implementation ("Tokenizer_T.cpp")
235 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
237 #include /**/ "ace/post.h"
239 #endif /* ACE_TOKENIZER_T_H */