KSquare Utilities
KKB::XmlTokenizer Class Reference

Manages the break down a stream into a set of logical tokens compatible with the XML format. More...

#include <XmlTokenizer.h>

Public Member Functions

 XmlTokenizer (TokenBufferPtr _in)
 Constructs a XmlTokenizer using the provided [[TokenBuffer]] _in as the data stream source. More...
 
 XmlTokenizer (const KKStr &_str)
 Manages the extraction of xml tokens from a KKStr instance; accomplishes this by building a [[TokenBufferStr]] around _str. More...
 
 XmlTokenizer (const KKStr &_fileName, bool &_fileOpened)
 
 ~XmlTokenizer ()
 
bool EndOfFile ()
 
KKStrPtr GetNextToken ()
 Will retrieve the next token in the stream which will be either a tag token or up to one line of the content part of an element. If it is a content token it may end with a '
' character. The idea is tat when reading content we will never return more than one line of text at a time. More...
 
KKStrListPtr GetNextTokens (const KKStr &delToken)
 Returns a list of tokens up to and including the first occurrence of 'delToken'. More...
 
KKStrConstPtr operator[] (kkuint32 idx)
 
KKStrConstPtr Peek (kkuint32 idx)
 Allows you to look at future tokens in the stream; index of 0 would be the next token to be extracted. More...
 
void PushTokenOnFront (KKStrPtr t)
 places token at current position such that it will be the next token extracted from the stream. More...
 

Detailed Description

Manages the break down a stream into a set of logical tokens compatible with the XML format.

Author
Kurt Kramer

Breaks up a source KKStr, text file, or [[TokenBuffer]] into logical tokens compatible with the XML format. XmlStream utilizes this object to parse streams. XmlStream

Definition at line 25 of file XmlTokenizer.h.

Constructor & Destructor Documentation

XmlTokenizer::XmlTokenizer ( TokenBufferPtr  _in)

Constructs a XmlTokenizer using the provided [[TokenBuffer]] _in as the data stream source.

Does NOT take ownership of _in; next token extracted will be from current position in _in.

Parameters
_inWill retrieve tokens from starting from its current position; does not take ownership.

Definition at line 23 of file XmlTokenizer.cpp.

References XmlTokenizer().

Referenced by XmlTokenizer().

23  :
24 
25  atEndOfFile (false),
26  in (_in),
27  tokenList (),
28  weOwnTokenBuffer (false)
29 
30 #if defined(_LogStream_)
31  ,
32  logger1 ("C:\\Temp\\XmlTokenizer-1.txt"),
33  logger2 ("C:\\Temp\\XmlTokenizer-2.txt")
34 #endif
35 {
36  Initialize ();
37 }
XmlTokenizer::XmlTokenizer ( const KKStr _str)

Manages the extraction of xml tokens from a KKStr instance; accomplishes this by building a [[TokenBufferStr]] around _str.

Definition at line 41 of file XmlTokenizer.cpp.

References KKB::TokenBufferStr::TokenBufferStr(), and XmlTokenizer().

Referenced by XmlTokenizer().

41  :
42 
43  atEndOfFile (false),
44  in (NULL),
45  tokenList (),
46  weOwnTokenBuffer (false)
47 #if defined(_LogStream_)
48  ,
49  logger1 ("C:\\Temp\\XmlTokenizer-1.txt"),
50  logger2 ("C:\\Temp\\XmlTokenizer-2.txt")
51 #endif
52 {
53  in = new TokenBufferStr (_str);
54  weOwnTokenBuffer = true;
55  Initialize ();
56 }
XmlTokenizer::XmlTokenizer ( const KKStr _fileName,
bool &  _fileOpened 
)

Definition at line 60 of file XmlTokenizer.cpp.

References KKB::TokenBufferStream::TokenBufferStream(), KKB::TokenBuffer::Valid(), and XmlTokenizer().

Referenced by KKB::XmlStream::XmlStream(), and XmlTokenizer().

62  :
63 
64  atEndOfFile (false),
65  in (NULL),
66  tokenList (),
67  weOwnTokenBuffer (false)
68 #if defined(_LogStream_)
69  ,
70  logger1 ("C:\\Temp\\XmlTokenizer-1.txt"),
71  logger2 ("C:\\Temp\\XmlTokenizer-2.txt")
72 #endif
73 {
74  in = new TokenBufferStream (_fileName);
75  _fileOpened = (in->Valid ());
76  if (_fileOpened)
77  {
78  weOwnTokenBuffer = true;
79  Initialize ();
80  }
81 }
virtual bool Valid()=0
XmlTokenizer::~XmlTokenizer ( )

Definition at line 86 of file XmlTokenizer.cpp.

87 {
88  if (weOwnTokenBuffer)
89  {
90  delete in;
91  in = NULL;
92  }
93 }

Member Function Documentation

bool XmlTokenizer::EndOfFile ( )

Indicates if there anymore tokens that can be extracted.

Definition at line 224 of file XmlTokenizer.cpp.

225 {
226 // if (tokenList.QueueSize () == 0)
227 // return true;
228  while ((tokenList.size () < 1) && (!atEndOfFile))
229  ReadInNextLogicalToken ();
230 
231  return (tokenList.size () < 1);
232 } /* EndOfFile */
KKStrPtr XmlTokenizer::GetNextToken ( )

Will retrieve the next token in the stream which will be either a tag token or up to one line of the content part of an element. If it is a content token it may end with a '
' character. The idea is tat when reading content we will never return more than one line of text at a time.

Definition at line 135 of file XmlTokenizer.cpp.

Referenced by KKB::XmlStream::GetNextContent(), KKB::XmlStream::GetNextToken(), and GetNextTokens().

136 {
137  while ((tokenList.size () < 1) && (!atEndOfFile))
138  ReadInNextLogicalToken ();
139 
140  if (tokenList.size () < 1)
141  {
142  #if defined(_LogStream_)
143  logger2 << "GetNextToken return NULL" << endl;
144  logger2.flush ();
145  #endif
146  return NULL;
147  }
148 
149  kkuint32 s = tokenList.size ();
150 
151  KKStrPtr t = tokenList.front ();
152  tokenList.pop_front ();
153 
154  #if defined(_LogStream_)
155  logger2 << "GetNextToken size[" << s << "] :" << (t ? (*t) : "NULL") << endl;
156  logger2.flush ();
157  #endif
158 
159  return t;
160 } /* GetNextToken */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
KKStrListPtr XmlTokenizer::GetNextTokens ( const KKStr delToken)

Returns a list of tokens up to and including the first occurrence of 'delToken'.

Will return a list of tokens up to and including the first occurrence if 'delToken'.

Caller will take ownership of the returned tokens, and be responsible for deleting them.

Definition at line 167 of file XmlTokenizer.cpp.

References KKB::KKStr::Empty(), GetNextToken(), KKB::KKStrList::KKStrList(), and KKB::KKStr::operator!=().

168 {
169  if (delToken.Empty ())
170  return NULL;
171 
172  if (atEndOfFile && (tokenList.size () < 1))
173  return NULL;
174 
175  KKStrPtr t = GetNextToken ();
176  if (t == NULL)
177  return NULL;
178 
179  KKStrListPtr tokens = new KKStrList (true);
180  while ((t != NULL) && (*t != delToken))
181  {
182  tokens->PushOnBack (t);
183  t = GetNextToken ();
184  }
185 
186  if (t)
187  tokens->PushOnBack (t);
188 
189  return tokens;
190 } /* GetNextTokens */
bool Empty() const
Definition: KKStr.h:241
virtual void PushOnBack(EntryPtr _entry)
Definition: KKQueue.h:398
KKStrPtr GetNextToken()
Will retrieve the next token in the stream which will be either a tag token or up to one line of the ...
KKStrConstPtr XmlTokenizer::operator[] ( kkuint32  idx)

Returns pointers to following Tokens in the stream where idx==0 indicates the next token.

Definition at line 481 of file XmlTokenizer.cpp.

References Peek().

482 {
483  return Peek (idx);
484 } /* operator[] */
KKStrConstPtr Peek(kkuint32 idx)
Allows you to look at future tokens in the stream; index of 0 would be the next token to be extracted...
KKStrConstPtr XmlTokenizer::Peek ( kkuint32  idx)

Allows you to look at future tokens in the stream; index of 0 would be the next token to be extracted.

Definition at line 202 of file XmlTokenizer.cpp.

Referenced by KKB::XmlStream::GetNextContent(), and operator[]().

203 {
204  while ((tokenList.size () < (idx + 1)) && !atEndOfFile)
205  ReadInNextLogicalToken ();
206 
207  if (idx >= tokenList.size ())
208  {
209  #if defined(_LogStream_)
210  logger2 << "Peek idx[" << idx << "] returning NULL" << endl;
211  #endif
212  return NULL;
213  }
214 
215  #if defined(_LogStream_)
216  logger2 << "Peek idx[" << idx << "] :" << *(tokenList[idx]) << endl;
217  #endif
218 
219  return tokenList[idx];
220 } /* Peek */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
void XmlTokenizer::PushTokenOnFront ( KKStrPtr  t)

places token at current position such that it will be the next token extracted from the stream.

Definition at line 194 of file XmlTokenizer.cpp.

195 {
196  tokenList.push_front (t);
197 }

The documentation for this class was generated from the following files: