SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TXmlParser Class Reference

#include <xml.h>

Collaboration diagram for TXmlParser:

Public Member Functions

 TXmlParser (const PSIn &_SIn)
 
TXmlLxSym GetSym ()
 
TXmlLxSym GetSym (TChA &_SymStr)
 
TXmlLxSym PeekSym ()
 
TXmlLxSym PeekSym (TChA &_SymStr)
 
void SkipTillTag (const TChA &_SymStr)
 
TXmlLxSym GetTag (const TChA &TagStr)
 
void GetTagVal (const TChA &TagStr, TChA &TagVal)
 

Static Public Member Functions

static PXmlParser New (const PSIn &SIn)
 
static void GetPlainStrFromXmlStr (const TChA &XmlStr, TChA &PlainChA)
 

Public Attributes

TXmlLxSym Sym
 
TXmlLxSym NextSym
 
TChA SymStr
 
TChA NextSymStr
 

Private Member Functions

char GetCh ()
 

Private Attributes

TCRef CRef
 
PSIn SIn
 
TSInRSIn
 
TChA _SymStr
 

Friends

class TPt< TXmlParser >
 

Detailed Description

Definition at line 397 of file xml.h.

Constructor & Destructor Documentation

TXmlParser::TXmlParser ( const PSIn _SIn)
inline

Definition at line 409 of file xml.h.

Referenced by New().

409 : SIn(_SIn), RSIn(*SIn), Sym(xsyUndef), NextSym(xsyUndef) { }
TXmlLxSym NextSym
Definition: xml.h:404
TSIn & RSIn
Definition: xml.h:401
TXmlLxSym Sym
Definition: xml.h:404
Definition: xml.h:90
PSIn SIn
Definition: xml.h:400

Here is the caller graph for this function:

Member Function Documentation

char TXmlParser::GetCh ( )
inlineprivate

Definition at line 407 of file xml.h.

References TSIn::Eof(), TCh::EofCh, TSIn::GetCh(), and RSIn.

Referenced by GetSym().

407 { return (! RSIn.Eof()) ? RSIn.GetCh() : TCh::EofCh; }
TSIn & RSIn
Definition: xml.h:401
static const char EofCh
Definition: dt.h:1037
virtual bool Eof()=0
virtual char GetCh()=0

Here is the call graph for this function:

Here is the caller graph for this function:

void TXmlParser::GetPlainStrFromXmlStr ( const TChA XmlStr,
TChA PlainChA 
)
static

Definition at line 1531 of file xml.cpp.

References TChA::Clr(), TChA::CStr(), TChA::Empty(), forever, TCh::GetHex(), TCh::GetNum(), TCh::IsHex(), and TCh::IsNum().

Referenced by GetSym().

1531  {
1532  static TChA EntityNm;
1533  PlainChA.Clr();
1534  const char *Ch = XmlStr.CStr();
1535  while (*Ch){
1536  if (*Ch!='&'){ PlainChA+=*Ch; Ch++; }
1537  else {
1538  if (*++Ch=='#'){
1539  TChA RefChA; int RefCd=0;
1540  if (*++Ch=='x'){
1541  forever { Ch++;
1542  if (TCh::IsHex(*Ch)){ RefChA+=*Ch; RefCd=RefCd*16+TCh::GetHex(*Ch); }
1543  else { break; } }
1544  } else { // decimal character code
1545  forever {
1546  if (TCh::IsNum(*Ch)){ RefChA+=*Ch; RefCd=RefCd*10+TCh::GetNum(*Ch); }
1547  else { break; } Ch++; }
1548  }
1549  if ((!RefChA.Empty())&&(*Ch==';')){
1550  Ch++; const uchar RefCh=uchar(RefCd); PlainChA+=RefCh; }
1551  } else {
1552  EntityNm.Clr();
1553  while ((*Ch)&&(*Ch!=';')){EntityNm+=*Ch; Ch++;}
1554  if ((!EntityNm.Empty())&&(*Ch==';')){ Ch++;
1555  if (EntityNm=="quot"){PlainChA+='"';}
1556  else if (EntityNm=="amp"){PlainChA+='&';}
1557  else if (EntityNm=="apos"){PlainChA+='\'';}
1558  else if (EntityNm=="lt"){PlainChA+='<';}
1559  else if (EntityNm=="gt"){PlainChA+='>';}
1560  }
1561  }
1562  }
1563  }
1564 }
static bool IsHex(const char &Ch)
Definition: dt.h:1067
static bool IsNum(const char &Ch)
Definition: dt.h:1064
#define forever
Definition: bd.h:6
bool Empty() const
Definition: dt.h:260
void Clr()
Definition: dt.h:258
static int GetHex(const char &Ch)
Definition: dt.h:1069
char * CStr()
Definition: dt.h:255
static int GetNum(const char &Ch)
Definition: dt.h:1066
unsigned char uchar
Definition: bd.h:10
Definition: dt.h:201

Here is the call graph for this function:

Here is the caller graph for this function:

TXmlLxSym TXmlParser::GetSym ( )

Definition at line 1457 of file xml.cpp.

References _SymStr, TChA::Clr(), TChA::CStr(), TSIn::Eof(), TCh::EofCh, GetCh(), GetPlainStrFromXmlStr(), TCh::IsWs(), TChA::Len(), NextSym, NextSymStr, TSIn::PeekCh(), TChA::Push(), RSIn, Sym, SymStr, xsyEof, xsyETag, xsySTag, xsyStr, and xsyUndef.

Referenced by GetSym(), GetTag(), GetTagVal(), PeekSym(), and SkipTillTag().

1457  {
1458  if (NextSym != xsyUndef) {
1461  return Sym;
1462  }
1463  SymStr.Clr();
1464  char Ch;
1465  while (TCh::IsWs(Ch=GetCh())) { }
1466  if (Ch == TCh::EofCh) { Sym = xsyEof; return xsyEof; }
1467  if (Ch == '<') { // load tag
1468  Ch = GetCh();
1469  if (Ch == '/') { Sym = xsyETag; }
1470  else { Sym = xsySTag; SymStr.Push(Ch); }
1471  while((Ch=GetCh())!='>' && Ch!=TCh::EofCh) { SymStr.Push(Ch); }
1472  const int StrLen = SymStr.Len();
1473  if (StrLen > 1 && SymStr[StrLen-1] == '/') {
1474  Sym = xsyETag; SymStr[StrLen-1] = 0;
1475  for (char *c = SymStr.CStr()+StrLen-2; TCh::IsWs(*c); c--) { *c=0; }
1476  }
1477  } else { // load string
1478  _SymStr.Clr(); _SymStr.Push(Ch);
1479  while (! RSIn.Eof() && RSIn.PeekCh() != '<') { _SymStr.Push(GetCh()); }
1481  Sym = xsyStr;
1482  }
1483  if (Ch == TCh::EofCh) { SymStr.Clr(); Sym = xsyEof; return xsyEof; }
1484  return Sym;
1485 }
TChA NextSymStr
Definition: xml.h:405
TChA SymStr
Definition: xml.h:405
TXmlLxSym NextSym
Definition: xml.h:404
Definition: xml.h:94
void Clr()
Definition: dt.h:258
TSIn & RSIn
Definition: xml.h:401
int Len() const
Definition: dt.h:259
TChA _SymStr
Definition: xml.h:402
static const char EofCh
Definition: dt.h:1037
static bool IsWs(const char &Ch)
Definition: dt.h:1060
char GetCh()
Definition: xml.h:407
char * CStr()
Definition: dt.h:255
virtual bool Eof()=0
Definition: xml.h:93
Definition: xml.h:93
TXmlLxSym Sym
Definition: xml.h:404
Definition: xml.h:90
Definition: xml.h:93
static void GetPlainStrFromXmlStr(const TChA &XmlStr, TChA &PlainChA)
Definition: xml.cpp:1531
void Push(const char &Ch)
Definition: dt.h:264
virtual char PeekCh()=0

Here is the call graph for this function:

Here is the caller graph for this function:

TXmlLxSym TXmlParser::GetSym ( TChA _SymStr)

Definition at line 1487 of file xml.cpp.

References GetSym(), Sym, and SymStr.

1487  {
1488  GetSym();
1489  _SymStr = SymStr;
1490  return Sym;
1491 }
TChA SymStr
Definition: xml.h:405
TXmlLxSym GetSym()
Definition: xml.cpp:1457
TXmlLxSym Sym
Definition: xml.h:404

Here is the call graph for this function:

TXmlLxSym TXmlParser::GetTag ( const TChA TagStr)

Definition at line 1524 of file xml.cpp.

References TChA::CStr(), EAssertR, TStr::Fmt(), GetSym(), Sym, and SymStr.

Referenced by GetTagVal().

1524  {
1525  GetSym();
1526  EAssertR(TagStr==SymStr, TStr::Fmt("Expected xml symbol '%s'. Found '%s'",
1527  TagStr.CStr(), SymStr.CStr()).CStr());
1528  return Sym;
1529 }
TChA SymStr
Definition: xml.h:405
TXmlLxSym GetSym()
Definition: xml.cpp:1457
char * CStr()
Definition: dt.h:255
TXmlLxSym Sym
Definition: xml.h:404
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283

Here is the call graph for this function:

Here is the caller graph for this function:

void TXmlParser::GetTagVal ( const TChA TagStr,
TChA TagVal 
)

Definition at line 1518 of file xml.cpp.

References TChA::CStr(), EAssertR, TStr::Fmt(), GetSym(), GetTag(), SymStr, xsyETag, xsySTag, and xsyStr.

1518  {
1519  EAssertR(GetTag(TagStr) == xsySTag, TStr::Fmt("Expected '<%s>'. Found '%s'", TagStr.CStr(), SymStr.CStr()).CStr());
1520  EAssertR(GetSym(TagVal) == xsyStr, "Expected string tag.");
1521  EAssertR(GetTag(TagStr) == xsyETag, TStr::Fmt("Expected '</%s>'. Found '%s'", TagStr.CStr(), SymStr.CStr()).CStr());
1522 }
TChA SymStr
Definition: xml.h:405
TXmlLxSym GetSym()
Definition: xml.cpp:1457
TXmlLxSym GetTag(const TChA &TagStr)
Definition: xml.cpp:1524
char * CStr()
Definition: dt.h:255
Definition: xml.h:93
Definition: xml.h:93
Definition: xml.h:93
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283

Here is the call graph for this function:

static PXmlParser TXmlParser::New ( const PSIn SIn)
inlinestatic

Definition at line 410 of file xml.h.

References TXmlParser().

410 { return new TXmlParser(SIn); }
TXmlParser(const PSIn &_SIn)
Definition: xml.h:409

Here is the call graph for this function:

TXmlLxSym TXmlParser::PeekSym ( )

Definition at line 1493 of file xml.cpp.

References GetSym(), NextSym, NextSymStr, Sym, SymStr, and xsyUndef.

Referenced by PeekSym(), and SkipTillTag().

1493  {
1494  if (NextSym == xsyUndef) {
1495  const TXmlLxSym TmpSim=Sym;
1496  const TChA TmpSymStr=SymStr;
1498  Sym=TmpSim;
1499  SymStr=TmpSymStr;
1500  }
1501  return NextSym;
1502 }
TChA NextSymStr
Definition: xml.h:405
TChA SymStr
Definition: xml.h:405
TXmlLxSym NextSym
Definition: xml.h:404
TXmlLxSym GetSym()
Definition: xml.cpp:1457
TXmlLxSym Sym
Definition: xml.h:404
Definition: xml.h:90
Definition: dt.h:201
TXmlLxSym
Definition: xml.h:89

Here is the call graph for this function:

Here is the caller graph for this function:

TXmlLxSym TXmlParser::PeekSym ( TChA _SymStr)

Definition at line 1504 of file xml.cpp.

References NextSym, NextSymStr, and PeekSym().

1504  {
1505  PeekSym();
1506  _SymStr = NextSymStr;
1507  return NextSym;
1508 }
TChA NextSymStr
Definition: xml.h:405
TXmlLxSym NextSym
Definition: xml.h:404
TXmlLxSym PeekSym()
Definition: xml.cpp:1493

Here is the call graph for this function:

void TXmlParser::SkipTillTag ( const TChA _SymStr)

Definition at line 1510 of file xml.cpp.

References GetSym(), NextSymStr, PeekSym(), and xsyEof.

1510  {
1511  while(PeekSym() != xsyEof) {
1512  if (NextSymStr == _SymStr) { return; }
1513  GetSym();
1514  }
1515 }
TChA NextSymStr
Definition: xml.h:405
Definition: xml.h:94
TXmlLxSym GetSym()
Definition: xml.cpp:1457
TXmlLxSym PeekSym()
Definition: xml.cpp:1493

Here is the call graph for this function:

Friends And Related Function Documentation

friend class TPt< TXmlParser >
friend

Definition at line 422 of file xml.h.

Member Data Documentation

TChA TXmlParser::_SymStr
private

Definition at line 402 of file xml.h.

Referenced by GetSym().

TCRef TXmlParser::CRef
private

Definition at line 399 of file xml.h.

TXmlLxSym TXmlParser::NextSym

Definition at line 404 of file xml.h.

Referenced by GetSym(), and PeekSym().

TChA TXmlParser::NextSymStr

Definition at line 405 of file xml.h.

Referenced by GetSym(), PeekSym(), and SkipTillTag().

TSIn& TXmlParser::RSIn
private

Definition at line 401 of file xml.h.

Referenced by GetCh(), and GetSym().

PSIn TXmlParser::SIn
private

Definition at line 400 of file xml.h.

TXmlLxSym TXmlParser::Sym

Definition at line 404 of file xml.h.

Referenced by GetSym(), GetTag(), and PeekSym().

TChA TXmlParser::SymStr

Definition at line 405 of file xml.h.

Referenced by GetSym(), GetTag(), GetTagVal(), and PeekSym().


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