ProteoWizard
Classes | Functions
pwiz::minimxml::SAXParser Namespace Reference

An extended SAX interface for custom XML stream parsing. More...

Classes

class  Handler
 SAX event handler interface. More...
 
class  saxstring
 

Functions

PWIZ_API_DECL size_t count_trail_ws (const char *data, size_t len)
 
PWIZ_API_DECL void unescapeXML (char *str)
 
PWIZ_API_DECL void unescapeXML (std::string &str)
 
std::ostream & operator<< (std::ostream &os, const saxstring &s)
 
template<typename Target >
Target textToValue (const char *txt)
 
template<>
float textToValue (const char *txt)
 
template<>
double textToValue (const char *txt)
 
template<>
int textToValue (const char *txt)
 
template<>
char textToValue (const char *txt)
 
template<>
long textToValue (const char *txt)
 
template<>
unsigned int textToValue (const char *txt)
 
template<>
unsigned long textToValue (const char *txt)
 
bool istrue (const char *t)
 
template<>
bool textToValue (const char *txt)
 
template<>
boost::logic::tribool textToValue (const char *txt)
 
template<>
std::string textToValue (const char *txt)
 
PWIZ_API_DECL void parse (std::istream &is, Handler &handler)
 Extract a single XML element from the istream, sending SAX events to the handler. More...
 

Detailed Description

An extended SAX interface for custom XML stream parsing.

Use cases:

Function Documentation

§ count_trail_ws()

PWIZ_API_DECL size_t pwiz::minimxml::SAXParser::count_trail_ws ( const char *  data,
size_t  len 
)

§ unescapeXML() [1/2]

PWIZ_API_DECL void pwiz::minimxml::SAXParser::unescapeXML ( char *  str)

§ unescapeXML() [2/2]

PWIZ_API_DECL void pwiz::minimxml::SAXParser::unescapeXML ( std::string &  str)

§ operator<<()

std::ostream& pwiz::minimxml::SAXParser::operator<< ( std::ostream &  os,
const saxstring s 
)
inline

Definition at line 218 of file SAXParser.hpp.

References pwiz::minimxml::SAXParser::saxstring::c_str(), and textToValue().

219 {
220  os << s.c_str();
221  return os;
222 }

§ textToValue() [1/11]

template<typename Target >
Target pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 229 of file SAXParser.hpp.

References ATOF, istrue(), and textToValue().

Referenced by operator<<(), and textToValue().

230 {
231  return (float) ATOF( txt ) ;
232 }
#define ATOF(x)

§ textToValue() [2/11]

template<>
float pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 229 of file SAXParser.hpp.

References ATOF.

230 {
231  return (float) ATOF( txt ) ;
232 }
#define ATOF(x)

§ textToValue() [3/11]

template<>
double pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 234 of file SAXParser.hpp.

References ATOF.

235 {
236  return ATOF( txt );
237 }
#define ATOF(x)

§ textToValue() [4/11]

template<>
int pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 239 of file SAXParser.hpp.

240 {
241  return atoi(txt);
242 }

§ textToValue() [5/11]

template<>
char pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 244 of file SAXParser.hpp.

245 {
246  return *(txt);
247 }

§ textToValue() [6/11]

template<>
long pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 249 of file SAXParser.hpp.

250 {
251  return atol(txt);
252 }

§ textToValue() [7/11]

template<>
unsigned int pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 254 of file SAXParser.hpp.

255 {
256  return (unsigned int) strtoul( txt, NULL, 10 );
257 }

§ textToValue() [8/11]

template<>
unsigned long pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 259 of file SAXParser.hpp.

References textToValue().

260 {
261  return strtoul( txt, NULL, 10 );
262 }

§ istrue()

bool pwiz::minimxml::SAXParser::istrue ( const char *  t)
inline

Definition at line 286 of file SAXParser.hpp.

Referenced by textToValue().

287 {
288  return strcmp(t, "0") && strcmp(t,"false"); // as in optimized_lexical_cast.h
289 }

§ textToValue() [9/11]

template<>
bool pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 291 of file SAXParser.hpp.

References istrue().

292 {
293  return istrue(txt);
294 }
bool istrue(const char *t)
Definition: SAXParser.hpp:286

§ textToValue() [10/11]

template<>
boost::logic::tribool pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 296 of file SAXParser.hpp.

References istrue().

297 {
298  using namespace boost::logic;
299  if (!*txt)
300  return tribool(indeterminate);
301  else
302  {
303  bool b = istrue(txt);
304  return tribool(b);
305  }
306 }
bool istrue(const char *t)
Definition: SAXParser.hpp:286

§ textToValue() [11/11]

template<>
std::string pwiz::minimxml::SAXParser::textToValue ( const char *  txt)
inline

Definition at line 308 of file SAXParser.hpp.

Referenced by operator<<(), and textToValue().

309 {
310  return std::string( txt );
311 }

§ parse()

PWIZ_API_DECL void pwiz::minimxml::SAXParser::parse ( std::istream &  is,
Handler handler 
)

Extract a single XML element from the istream, sending SAX events to the handler.

Behavior:

  • Parser returns when it completes reading of the first element it encounters.
  • Parser returns immediately if the Handler returns Status::Done when handling an event.
  • On startElement(), Handler may delegate handling to a sub-Handler, which will receive the same startElement() event. The sub-Handler pointer will remain on the parser's Handler stack until it handles the corresponding endElement(). Caution: The sub-Handler pointer must remain valid while it is on the Handler stack, so it cannot point to a local object that goes out of scope when Handler:startElement() returns.

Notes:

  • Start tags with end marker '/' generate two events, e.g.
    will generate events startElement("br", ...) and endElement("br").

Referenced by pwiz::minimxml::SAXParser::Handler::getAttribute().