Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

cppdom::xmlstream_iterator Class Reference

xml input stream iterator an iterator through all XMLToken contained in the xml input stream. More...

#include <xmltokenizer.h>

Inheritance diagram for cppdom::xmlstream_iterator:

Inheritance graph
[legend]
Collaboration diagram for cppdom::xmlstream_iterator:

Collaboration graph
[legend]
List of all members.

Public Methods

 xmlstream_iterator (std::istream &in, XMLLocation &loc)
 ctor. More...


Protected Methods

void getNext ()
bool isLiteral (char c)
bool isWhiteSpace (char c)
bool isNewLine (char c)
bool isStringDelimiter (char c)

Protected Attributes

bool mCdataMode
 cdata-mode doesn't care for whitespaces in generic strings. More...

char mPutbackChar
 char which was put back internally. More...


Detailed Description

xml input stream iterator an iterator through all XMLToken contained in the xml input stream.

Definition at line 166 of file xmltokenizer.h.


Constructor & Destructor Documentation

cppdom::xmlstream_iterator::xmlstream_iterator std::istream &    in,
XMLLocation   loc
 

ctor.

Definition at line 171 of file xmltokenizer.cpp.

00172       : XMLTokenizer(in, loc)
00173       , mCdataMode(false)
00174       , mPutbackChar(-1)
00175    {}


Member Function Documentation

void cppdom::xmlstream_iterator::getNext   [protected, virtual]
 

Todo:
check for instr.eof()

Implements cppdom::XMLTokenizer.

Definition at line 178 of file xmltokenizer.cpp.

References isLiteral(), isNewLine(), isStringDelimiter(), isWhiteSpace(), mCdataMode, cppdom::XMLTokenizer::mCurToken, cppdom::XMLTokenizer::mInput, cppdom::XMLTokenizer::mLocation, mPutbackChar, cppdom::XMLTokenizer::mTokenStack, and cppdom::XMLLocation::step().

00179    {
00180       // first use the token stack if filled
00181       if (mTokenStack.size() != 0)
00182       {
00183          // get the token from the stack and return it
00184          XMLToken tok;
00185          mCurToken = mTokenStack.top();
00186          mTokenStack.pop();
00187 
00188          return;
00189       }
00190 
00191       bool finished = false;
00192 
00193       std::string generic;
00194 
00195       // get next char
00196       char c;
00197 
00198       do
00199       {
00200          if (mPutbackChar == char(-1))
00201          {
00202             c = mInput.get();
00203             mLocation.step();
00204          }
00205          else
00206          {
00207             c = mPutbackChar;
00208             mPutbackChar = char(-1);
00209             mLocation.step();
00210          }
00211 
00212          // do we have an eof?
00213          // TODO: check for instr.eof()
00214          if (c == char(EOF))
00215          {
00216             if (generic.length() != 0)
00217             {
00218                mCurToken = c;
00219                return;
00220             }
00221             else
00222             {
00223                break;
00224             }
00225          }
00226 
00227          // is it a literal?
00228          if (isLiteral(c))
00229          {
00230             mCdataMode = false;
00231             if (generic.length() == 0)
00232             {
00233                mCurToken = c;
00234 
00235                // quick fix for removing set_cdataMode() functionality
00236                if (c == '>')
00237                {
00238                   mCdataMode = true;
00239                }
00240 
00241                return;
00242             }
00243             mPutbackChar = c;
00244             mLocation.step(-1);
00245             break;
00246          }
00247 
00248          // a string delimiter and not in cdata mode?
00249          if (isStringDelimiter(c) && !mCdataMode)
00250          {
00251             generic = c;
00252             char delim = c;
00253             do
00254             {
00255                c = mInput.get();
00256                mLocation.step();
00257                if (c == char(EOF))
00258                {
00259                   break;
00260                }
00261                generic += c;
00262             }
00263             while (c != delim);
00264             break;
00265          }
00266 
00267          // a whitespace?
00268          if (isWhiteSpace(c))
00269          {
00270             if (generic.length() == 0)
00271             {
00272                continue;
00273             }
00274             else
00275             {
00276                if (!mCdataMode)
00277                {
00278                   break;
00279                }
00280             }
00281          }
00282 
00283          // a newline char?
00284          if (isNewLine(c) )
00285          {
00286             if (mCdataMode && generic.length() != 0)
00287             {
00288                c = ' ';
00289             }
00290             else
00291             {
00292                continue;
00293             }
00294          }
00295 
00296          // add to generic string
00297          generic += c;
00298       }
00299       while (!finished);
00300 
00301       // set the generic string
00302       mCurToken = generic;
00303    }

bool cppdom::xmlstream_iterator::isLiteral char    c [protected]
 

Definition at line 306 of file xmltokenizer.cpp.

Referenced by getNext().

00307    {
00308       switch(c)
00309       {
00310       case '?':
00311       case '=':
00312       case '!':
00313       case '/':
00314          if (mCdataMode)
00315          {
00316             return false;
00317          }
00318       case '<':
00319       case '>':
00320          return true;
00321       }
00322       return false;
00323    }

bool cppdom::xmlstream_iterator::isNewLine char    c [protected]
 

Definition at line 338 of file xmltokenizer.cpp.

References cppdom::XMLTokenizer::mLocation, and cppdom::XMLLocation::newline().

Referenced by getNext().

00339    {
00340       switch(c)
00341       {
00342       case '\n':
00343          mLocation.newline();
00344       case '\r':
00345          return true;
00346       }
00347       return false;
00348    }

bool cppdom::xmlstream_iterator::isStringDelimiter char    c [protected]
 

Definition at line 351 of file xmltokenizer.cpp.

Referenced by getNext().

00352    {
00353       switch(c)
00354       {
00355       case '\"':
00356       case '\'':
00357          return true;
00358       }
00359       return false;
00360    }

bool cppdom::xmlstream_iterator::isWhiteSpace char    c [protected]
 

Definition at line 326 of file xmltokenizer.cpp.

Referenced by getNext().

00327    {
00328       switch(c)
00329       {
00330       case ' ':
00331       case '\t':
00332          return true;
00333       }
00334       return false;
00335    }


Member Data Documentation

bool cppdom::xmlstream_iterator::mCdataMode [protected]
 

cdata-mode doesn't care for whitespaces in generic strings.

Definition at line 182 of file xmltokenizer.h.

Referenced by getNext().

char cppdom::xmlstream_iterator::mPutbackChar [protected]
 

char which was put back internally.

Definition at line 185 of file xmltokenizer.h.

Referenced by getNext().


The documentation for this class was generated from the following files:
Generated on Thu Jan 2 21:29:22 2003 for cppdom by doxygen1.2.15