1 #ifndef ACE_TOKENIZER_T_CPP
2 #define ACE_TOKENIZER_T_CPP
5 #include "ace/Malloc_Base.h"
6 #include "ace/String_Base.h"
7 #include "ace/OS_NS_string.h"
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 template <class ACE_CHAR_T
>
12 ACE_Tokenizer_T
<ACE_CHAR_T
>::ACE_Tokenizer_T (ACE_CHAR_T
*buffer
)
20 template <class ACE_CHAR_T
>
22 ACE_Tokenizer_T
<ACE_CHAR_T
>::delimiter (ACE_CHAR_T d
)
24 if (delimiter_index_
== MAX_DELIMITERS
)
27 delimiters_
[delimiter_index_
].delimiter_
= d
;
28 delimiters_
[delimiter_index_
].replace_
= 0;
33 template <class ACE_CHAR_T
>
35 ACE_Tokenizer_T
<ACE_CHAR_T
>::delimiter_replace (ACE_CHAR_T d
,
36 ACE_CHAR_T replacement
)
38 // Make it possible to replace delimiters on-the-fly, e.g., parse
39 // string until certain token count and then copy rest of the
41 for (int i
= 0; i
< delimiter_index_
; i
++)
42 if (delimiters_
[i
].delimiter_
== d
)
44 delimiters_
[i
].replacement_
= replacement
;
45 delimiters_
[i
].replace_
= 1;
49 if (delimiter_index_
>= MAX_DELIMITERS
)
52 delimiters_
[delimiter_index_
].delimiter_
= d
;
53 delimiters_
[delimiter_index_
].replacement_
= replacement
;
54 delimiters_
[delimiter_index_
].replace_
= 1;
59 template <class ACE_CHAR_T
>
61 ACE_Tokenizer_T
<ACE_CHAR_T
>::preserve_designators (ACE_CHAR_T start
,
65 if (preserves_index_
== MAX_PRESERVES
)
68 preserves_
[preserves_index_
].start_
= start
;
69 preserves_
[preserves_index_
].stop_
= stop
;
70 preserves_
[preserves_index_
].strip_
= strip
;
75 template <class ACE_CHAR_T
>
77 ACE_Tokenizer_T
<ACE_CHAR_T
>::is_delimiter (ACE_CHAR_T d
,
83 for (int x
= 0; x
< delimiter_index_
; x
++)
84 if (delimiters_
[x
].delimiter_
== d
)
86 if (delimiters_
[x
].replace_
)
88 r
= delimiters_
[x
].replacement_
;
97 template <class ACE_CHAR_T
>
99 ACE_Tokenizer_T
<ACE_CHAR_T
>::is_preserve_designator (ACE_CHAR_T start
,
103 for (int x
= 0; x
< preserves_index_
; x
++)
104 if (preserves_
[x
].start_
== start
)
106 stop
= preserves_
[x
].stop_
;
107 strip
= preserves_
[x
].strip_
;
114 template <class ACE_CHAR_T
>
116 ACE_Tokenizer_T
<ACE_CHAR_T
>::next (void)
118 // Check if the previous pass was the last one in the buffer.
125 // Check if a buffer has been passed
131 ACE_CHAR_T replacement
= 0;
133 ACE_CHAR_T
*next_token
= 0;
135 // Skip all leading delimiters.
138 // Check for end of string.
139 if (buffer_
[index_
] == '\0')
141 // If we hit EOS at the start, return 0.
146 if (this->is_delimiter (buffer_
[index_
],
154 // When we reach this point, buffer_[index_] is a non-delimiter and
155 // not EOS - the start of our next_token.
156 next_token
= buffer_
+ index_
;
158 // A preserved region is it's own token.
161 if (this->is_preserve_designator (buffer_
[index_
],
167 if (buffer_
[index_
] == '\0')
173 if (buffer_
[index_
] == stop
)
179 // Skip start preserve designator.
181 // Zap the stop preserve designator.
182 buffer_
[index_
] = '\0';
183 // Increment to the next token.
190 // Step through finding the next delimiter or EOS.
196 // Check for delimiter.
197 if (this->is_delimiter (buffer_
[index_
],
201 // Replace the delimiter.
203 buffer_
[index_
] = replacement
;
205 // Move the pointer up and return.
210 // A preserve designator is NESTED inside this token
211 // We can't strip such preserve designators, just skip
212 // over them so that delimiters nested within arn't seen.
213 if (this->is_preserve_designator (buffer_
[index_
],
217 ++index_
; // Skip starting preserve_designator
218 while (('\0' != buffer_
[index_
]) && (stop
!= buffer_
[index_
]))
219 ++index_
; // Skip enclosed character
222 // Check for end of string.
223 if (buffer_
[index_
] == '\0')
234 // *************************************************************
237 ACE_END_VERSIONED_NAMESPACE_DECL
239 #endif /* ACE_TOKENIZER_T_CPP */