CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
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 ecal_dqm_sourceclient-live_cfg::cerr.

Referenced by SimpleSAXParser::parse().

22 {
23 #ifdef SIMPLE_SAX_PARSER_DEBUG
24  static char *debug_states[] = {
25  "IN_DOCUMENT",
26  "IN_BEGIN_TAG",
27  "IN_DONE",
28  "IN_BEGIN_ELEMENT",
29  "IN_ELEMENT_WHITESPACE",
30  "IN_END_ELEMENT",
31  "IN_ATTRIBUTE_KEY",
32  "IN_END_TAG",
33  "IN_DATA",
34  "IN_BEGIN_ATTRIBUTE_VALUE",
35  "IN_STRING",
36  "IN_END_ATTRIBUTE_VALUE",
37  "IN_STRING_ENTITY",
38  "IN_DATA_ENTITY"
39  };
40 
41  std::cerr << debug_states[state] << std::endl;
42 #endif
43 }
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 EnergyCorrector::c, hitfit::char, and i.

Referenced by SimpleSAXParser::getToken().

253 {
254  // if the passed first character is EOF or a separator,
255  // return an empty otherwise use it as first character
256  // of the buffer.
257  if (*firstChar == EOF || (int) separators[0] == *firstChar || strchr(separators + 1, *firstChar))
258  {
259  (*buffer)[0] = 0;
260  return true;
261  }
262  else
263  (*buffer)[0] = (char) *firstChar;
264 
265  size_t i = 1;
266 
267  while (true)
268  {
269  if (i >= *maxSize)
270  {
271  *maxSize += 1024;
272  *buffer = (char*) realloc(*buffer, *maxSize);
273  if (!*buffer)
274  return false;
275  }
276 
277  int c = in.get();
278 
279  if (c == EOF)
280  {
281  (*buffer)[i] = 0;
282  *firstChar = c;
283  return false;
284  }
285 
286  if (separators[0] == c || strchr(separators + 1, c))
287  {
288  (*buffer)[i] = 0;
289  *firstChar = c;
290  return true;
291  }
292 
293  (*buffer)[i++] = (char) c;
294  }
295 }
int i
Definition: DBlmapReader.cc:9
tuple maxSize
&#39;/store/data/Commissioning08/BeamHalo/RECO/StuffAlmostToP5_v1/000/061/642/10A0FE34-A67D-DD11-AD05-000...