SNAP Library 2.0, User Reference  2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TXmlParser Class Reference

#include <xml.h>

List of all members.

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.

: SIn(_SIn), RSIn(*SIn), Sym(xsyUndef), NextSym(xsyUndef) { }

Member Function Documentation

char TXmlParser::GetCh ( ) [inline, private]

Definition at line 407 of file xml.h.

{ return (! RSIn.Eof()) ? RSIn.GetCh() : TCh::EofCh; }
void TXmlParser::GetPlainStrFromXmlStr ( const TChA XmlStr,
TChA PlainChA 
) [static]

Definition at line 1531 of file xml.cpp.

                                                                         {
  static TChA EntityNm;
  PlainChA.Clr();
  const char *Ch = XmlStr.CStr();
  while (*Ch){
    if (*Ch!='&'){ PlainChA+=*Ch; Ch++; }
    else {
      if (*++Ch=='#'){
        TChA RefChA; int RefCd=0;
        if (*++Ch=='x'){
          forever {  Ch++;
            if (TCh::IsHex(*Ch)){ RefChA+=*Ch;  RefCd=RefCd*16+TCh::GetHex(*Ch); }
            else { break; } }
        } else { // decimal character code
          forever {
            if (TCh::IsNum(*Ch)){ RefChA+=*Ch; RefCd=RefCd*10+TCh::GetNum(*Ch); }
            else { break; } Ch++; }
        }
        if ((!RefChA.Empty())&&(*Ch==';')){
          Ch++;  const uchar RefCh=uchar(RefCd);  PlainChA+=RefCh; }
      } else {
        EntityNm.Clr();
        while ((*Ch)&&(*Ch!=';')){EntityNm+=*Ch; Ch++;}
        if ((!EntityNm.Empty())&&(*Ch==';')){  Ch++;
          if (EntityNm=="quot"){PlainChA+='"';}
          else if (EntityNm=="amp"){PlainChA+='&';}
          else if (EntityNm=="apos"){PlainChA+='\'';}
          else if (EntityNm=="lt"){PlainChA+='<';}
          else if (EntityNm=="gt"){PlainChA+='>';}
        }
      }
    }
  }
}

Definition at line 1457 of file xml.cpp.

                             {
  if (NextSym != xsyUndef) {
    Sym = NextSym;  NextSym=xsyUndef;
    SymStr=NextSymStr;  NextSymStr.Clr();
    return Sym;
  }
  SymStr.Clr();
  char Ch;
  while (TCh::IsWs(Ch=GetCh())) { }
  if (Ch == TCh::EofCh) { Sym = xsyEof; return xsyEof; }
  if (Ch == '<') { // load tag
    Ch = GetCh();
    if (Ch == '/') { Sym = xsyETag; }
    else { Sym = xsySTag;  SymStr.Push(Ch); }
    while((Ch=GetCh())!='>' && Ch!=TCh::EofCh) { SymStr.Push(Ch); }
    const int StrLen = SymStr.Len();
    if (StrLen > 1 && SymStr[StrLen-1] == '/') {
      Sym = xsyETag; SymStr[StrLen-1] = 0;
      for (char *c = SymStr.CStr()+StrLen-2; TCh::IsWs(*c); c--) { *c=0; }
    }
  } else { // load string
    _SymStr.Clr();  _SymStr.Push(Ch);
    while (! RSIn.Eof() && RSIn.PeekCh() != '<') { _SymStr.Push(GetCh()); }
    GetPlainStrFromXmlStr(_SymStr, SymStr);
    Sym = xsyStr;
  }
  if (Ch == TCh::EofCh) { SymStr.Clr(); Sym = xsyEof; return xsyEof; }
  return Sym;
}

Definition at line 1487 of file xml.cpp.

                                          {
  GetSym();
  _SymStr = SymStr;
  return Sym;
}
TXmlLxSym TXmlParser::GetTag ( const TChA TagStr)

Definition at line 1524 of file xml.cpp.

                                               {
  GetSym();
  EAssertR(TagStr==SymStr, TStr::Fmt("Expected xml symbol '%s'. Found '%s'",
    TagStr.CStr(), SymStr.CStr()).CStr());
  return Sym;
}
void TXmlParser::GetTagVal ( const TChA TagStr,
TChA TagVal 
)

Definition at line 1518 of file xml.cpp.

                                                           {
  EAssertR(GetTag(TagStr) == xsySTag, TStr::Fmt("Expected '<%s>'. Found '%s'", TagStr.CStr(), SymStr.CStr()).CStr());
  EAssertR(GetSym(TagVal) == xsyStr, "Expected string tag.");
  EAssertR(GetTag(TagStr) == xsyETag, TStr::Fmt("Expected '</%s>'. Found '%s'", TagStr.CStr(), SymStr.CStr()).CStr());
}
static PXmlParser TXmlParser::New ( const PSIn SIn) [inline, static]

Definition at line 410 of file xml.h.

{ return new TXmlParser(SIn); }

Definition at line 1493 of file xml.cpp.

                              {
  if (NextSym == xsyUndef) {
    const TXmlLxSym TmpSim=Sym;
    const TChA TmpSymStr=SymStr;
    NextSym=GetSym(NextSymStr);
    Sym=TmpSim;
    SymStr=TmpSymStr;
  }
  return NextSym;
}

Definition at line 1504 of file xml.cpp.

                                           {
  PeekSym();
  _SymStr = NextSymStr;
  return NextSym;
}
void TXmlParser::SkipTillTag ( const TChA _SymStr)

Definition at line 1510 of file xml.cpp.

                                                {
  while(PeekSym() != xsyEof) {
    if (NextSymStr == _SymStr) { return; }
    GetSym();
  }
}

Friends And Related Function Documentation

friend class TPt< TXmlParser > [friend]

Definition at line 422 of file xml.h.


Member Data Documentation

Definition at line 402 of file xml.h.

Definition at line 399 of file xml.h.

Definition at line 404 of file xml.h.

Definition at line 405 of file xml.h.

TSIn& TXmlParser::RSIn [private]

Definition at line 401 of file xml.h.

PSIn TXmlParser::SIn [private]

Definition at line 400 of file xml.h.

Definition at line 404 of file xml.h.

Definition at line 405 of file xml.h.


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