CMS 3D CMS Logo

Functions

/data/refman/pasoursint/CMSSW_5_3_0/src/Fireworks/Core/src/SimpleSAXParser.cc File Reference

#include "Fireworks/Core/src/SimpleSAXParser.h"

Go to the source code of this file.

Functions

void debug_state_machine (enum SimpleSAXParser::PARSER_STATES state)
bool fgettoken (std::istream &in, char **buffer, size_t *maxSize, const char *separators, int *firstChar)

Function Documentation

void debug_state_machine ( enum SimpleSAXParser::PARSER_STATES  state)

Definition at line 21 of file SimpleSAXParser.cc.

References dtNoiseDBValidation_cfg::cerr, and evf::utils::state.

Referenced by SimpleSAXParser::parse().

{
#ifdef SIMPLE_SAX_PARSER_DEBUG
  static char *debug_states[] = {
      "IN_DOCUMENT",
      "IN_BEGIN_TAG",
      "IN_DONE",
      "IN_BEGIN_ELEMENT",
      "IN_ELEMENT_WHITESPACE",
      "IN_END_ELEMENT",
      "IN_ATTRIBUTE_KEY",
      "IN_END_TAG",
      "IN_DATA",
      "IN_BEGIN_ATTRIBUTE_VALUE",
      "IN_STRING",
      "IN_END_ATTRIBUTE_VALUE",
      "IN_STRING_ENTITY",
      "IN_DATA_ENTITY"
   };

   std::cerr << debug_states[state] << std::endl;
#endif
}
bool fgettoken ( std::istream &  in,
char **  buffer,
size_t *  maxSize,
const char *  separators,
int *  firstChar 
)

Helper function which gets a token delimited by separator from the file and write it, 0 terminated in the buffer found in buffer.

Notice that if the token is larger than maxSize, the buffer is reallocated and maxSize is updated to the new size.

The trailing separator after a token is not put in the token and is left in the buffer. If nextChar is not 0, the delimiter is put there.

in the input stream to be parsed.

buffer a pointer to the buffer where to put the tokens. The buffer will be redimensioned accordingly, if the token is larger of the buffer.

maxSize, a pointer to the size of the buffer. Notice that in case the buffer is reallocated to have more space, maxSize is updated with the new size.

firstChar a pointer with the first character in the buffer, notice that the first charater in the stream must be obtained separately!!!

Returns:
whether or not we were able to get a (possibly empty) token from the file.

Definition at line 251 of file SimpleSAXParser.cc.

References trackerHits::c, and i.

Referenced by SimpleSAXParser::getToken().

{
  // if the passed first character is EOF or a separator,
  // return an empty otherwise use it as first character
  // of the buffer. 
  if (*firstChar == EOF || (int) separators[0] == *firstChar || strchr(separators + 1, *firstChar))
  {
    (*buffer)[0] = 0;
    return true;
  }
  else
    (*buffer)[0] = (char) *firstChar;

  size_t i = 1;

  while (true)
  {
    if (i >= *maxSize)
    {
      *maxSize += 1024;
      *buffer = (char*) realloc(*buffer, *maxSize);
      if (!*buffer)
         return false;
    }

    int c = in.get();

    if (c == EOF)
    {
       (*buffer)[i] = 0;
       *firstChar = c;
       return false;
    }
    
    if (separators[0] == c || strchr(separators + 1, c))
    {
      (*buffer)[i] = 0;
      *firstChar = c;
      return true;
    }

    (*buffer)[i++] = (char) c;
  }
}