SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TXmlLx Class Reference

#include <xml.h>

Public Member Functions

void SkipWs ()
 
 TXmlLx (const PSIn &_SIn, const TXmlSpacing &_Spacing=xspIntact)
 
TXmlLxoperator= (const TXmlLx &)
 
TXmlLxSym GetSym ()
 
TStr GetSymStr () const
 
void EThrow (const TStr &MsgStr) const
 
TStr GetFPosStr () const
 
void ClrArgV ()
 
void AddArg (const TStr &ArgNm, const TStr &ArgVal)
 
bool IsArgNm (const TStr &ArgNm) const
 
int GetArgs () const
 
void GetArg (const int &ArgN, TStr &ArgNm, TStr &ArgVal) const
 
TStr GetArgVal (const TStr &ArgNm, const TStr &DfVal=TStr()) const
 
bool IsEntityNm (const TStr &EntityNm, TStr &EntityVal) const
 
void PutEntityVal (const TStr &Nm, const TStr &Val)
 
bool IsPEntityNm (const TStr &EntityNm, TStr &EntityVal) const
 
void PutPEntityVal (const TStr &Nm, const TStr &Val)
 

Static Public Member Functions

static char GetArgValQCh (const TStr &ArgVal)
 
static TStr GetXmlLxSymStr (const TXmlLxSym &XmlLxSym)
 
static bool IsTagNm (const TStr &Str)
 
static TStr GetXmlStrFromPlainMem (const TMem &PlainMem)
 
static TStr GetXmlStrFromPlainStr (const TChA &PlainChA)
 
static TStr GetPlainStrFromXmlStr (const TStr &XmlStr)
 
static TStr GetUsAsciiStrFromXmlStr (const TStr &EntRefStr)
 
static TStr GetChRefFromYuEntRef (const TStr &YuEntRefStr)
 

Public Attributes

TXmlLxSym Sym
 
TChA TxtChA
 
TStr TagNm
 
TStrKdV ArgNmValKdV
 

Private Member Functions

uchar GetCh ()
 
void PutCh (const uchar &_Ch)
 
void PutStr (const TStr &Str)
 
void ToNrSpacing ()
 
void GetWs (const bool &IsRq)
 
TStr GetReference ()
 
void GetEq ()
 
TStr GetName ()
 
TStr GetName (const TStr &RqNm)
 
void GetComment ()
 
TStr GetAttValue ()
 
TStr GetVersionNum ()
 
TStr GetEncName ()
 
TStr GetStalVal ()
 
void GetXmlDecl ()
 
void GetPI ()
 
TStr GetSystemLiteral ()
 
TStr GetPubidLiteral ()
 
TStr GetPEReference ()
 
void GetExternalId ()
 
void GetNData ()
 
void GetDocTypeDecl ()
 
void GetElement ()
 
void GetAttList ()
 
TStr GetEntityValue ()
 
void GetEntity ()
 
void GetNotation ()
 
void GetCDSect ()
 

Private Attributes

PSIn SIn
 
TSInRSIn
 
TChA ChStack
 
uchar PrevCh
 
uchar Ch
 
int LnN
 
int LnChN
 
int ChN
 
TXmlSpacing Spacing
 
TStrStrH EntityNmToValH
 
TStrStrH PEntityNmToValH
 

Static Private Attributes

static TXmlChDef ChDef
 

Detailed Description

Definition at line 98 of file xml.h.

Constructor & Destructor Documentation

TXmlLx::TXmlLx ( const PSIn _SIn,
const TXmlSpacing _Spacing = xspIntact 
)
inline

Definition at line 145 of file xml.h.

145  :
146  SIn(_SIn), RSIn(*SIn),
147  ChStack(), PrevCh(' '), Ch(' '),
148  LnN(1), LnChN(0), ChN(0), Spacing(_Spacing),
149  EntityNmToValH(100), PEntityNmToValH(100),
150  Sym(xsyUndef), TxtChA(), TagNm(), ArgNmValKdV(10){GetCh();}
TStr TagNm
Definition: xml.h:141
TChA TxtChA
Definition: xml.h:140
PSIn SIn
Definition: xml.h:101
TChA ChStack
Definition: xml.h:103
TStrStrH EntityNmToValH
Definition: xml.h:113
uchar PrevCh
Definition: xml.h:104
uchar GetCh()
Definition: xml.cpp:260
TSIn & RSIn
Definition: xml.h:102
TStrKdV ArgNmValKdV
Definition: xml.h:142
int LnChN
Definition: xml.h:105
Definition: xml.h:90
TXmlSpacing Spacing
Definition: xml.h:106
int LnN
Definition: xml.h:105
TXmlLxSym Sym
Definition: xml.h:139
int ChN
Definition: xml.h:105
TStrStrH PEntityNmToValH
Definition: xml.h:113
uchar Ch
Definition: xml.h:104

Member Function Documentation

void TXmlLx::AddArg ( const TStr ArgNm,
const TStr ArgVal 
)
inline

Definition at line 161 of file xml.h.

161  {
162  ArgNmValKdV.Add(TStrKd(ArgNm, ArgVal));}
TStrKdV ArgNmValKdV
Definition: xml.h:142
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
TKeyDat< TStr, TStr > TStrKd
Definition: ds.h:405
void TXmlLx::ClrArgV ( )
inline

Definition at line 160 of file xml.h.

160 {ArgNmValKdV.Clr();}
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
TStrKdV ArgNmValKdV
Definition: xml.h:142
void TXmlLx::EThrow ( const TStr MsgStr) const

Definition at line 885 of file xml.cpp.

885  {
886  TChA FPosChA;
887  FPosChA+=" [File:"; FPosChA+=SIn->GetSNm();
888  FPosChA+=" Line:"; FPosChA+=TInt::GetStr(LnN);
889  FPosChA+=" Char:"; FPosChA+=TInt::GetStr(LnChN);
890  FPosChA+="]";
891  TStr FullMsgStr=MsgStr+FPosChA;
892  TExcept::Throw(FullMsgStr);
893 }
TStr GetStr() const
Definition: dt.h:1200
PSIn SIn
Definition: xml.h:101
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
int LnChN
Definition: xml.h:105
Definition: dt.h:201
Definition: dt.h:412
virtual TStr GetSNm() const
Definition: fl.cpp:20
int LnN
Definition: xml.h:105
void TXmlLx::GetArg ( const int &  ArgN,
TStr ArgNm,
TStr ArgVal 
) const
inline

Definition at line 166 of file xml.h.

166  {
167  ArgNm=ArgNmValKdV[ArgN].Key; ArgVal=ArgNmValKdV[ArgN].Dat;}
TStrKdV ArgNmValKdV
Definition: xml.h:142
int TXmlLx::GetArgs ( ) const
inline

Definition at line 165 of file xml.h.

165 {return ArgNmValKdV.Len();}
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TStrKdV ArgNmValKdV
Definition: xml.h:142
TStr TXmlLx::GetArgVal ( const TStr ArgNm,
const TStr DfVal = TStr() 
) const
inline

Definition at line 168 of file xml.h.

168  {
169  int ArgN=ArgNmValKdV.SearchForw(TStrKd(ArgNm));
170  if (ArgN==-1){return DfVal;} else {return ArgNmValKdV[ArgN].Dat;}}
TStrKdV ArgNmValKdV
Definition: xml.h:142
TSizeTy SearchForw(const TVal &Val, const TSizeTy &BValN=0) const
Returns the position of an element with value Val.
Definition: ds.h:1552
TKeyDat< TStr, TStr > TStrKd
Definition: ds.h:405
static char TXmlLx::GetArgValQCh ( const TStr ArgVal)
inlinestatic

Definition at line 171 of file xml.h.

171  {
172  if (ArgVal.IsChIn('\"')){return '\'';} else {return '\"';}}
bool IsChIn(const char &Ch) const
Definition: dt.h:556
void TXmlLx::GetAttList ( )
private

Definition at line 665 of file xml.cpp.

665  {
666  TxtChA.Clr();
667  while (Ch!='>'){
668  if (!ChDef.IsChar(Ch)){EThrow("Invalid Element character.");}
669  TxtChA+=Ch; GetCh();
670  }
671  GetCh();
672 }
bool IsChar(const uchar &Ch) const
Definition: xml.h:68
TChA TxtChA
Definition: xml.h:140
void Clr()
Definition: dt.h:258
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetAttValue ( )
private

Definition at line 457 of file xml.cpp.

457  {
458  // [10] AttValue ::= '"' ([^<&"] | Reference)* '"'
459  // | "'" ([^<&'] | Reference)* "'"
460  uchar QCh=Ch;
461  if ((QCh!='"')&&(QCh!='\'')){EThrow("Invalid attribute-value start.");}
462  TChA ValChA; GetCh();
463  forever {
464  if ((Ch=='<')||(!ChDef.IsChar(Ch))){
465  EThrow("Invalid attribute-value character.");}
466  if (Ch==QCh){GetCh(); break;} // final quote
467  else if (Ch=='&'){GetCh(); ValChA+=GetReference();} // reference
468  else {ValChA+=Ch; GetCh();} // usual char
469  }
470  return ValChA;
471 }
bool IsChar(const uchar &Ch) const
Definition: xml.h:68
#define forever
Definition: bd.h:6
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
unsigned char uchar
Definition: bd.h:10
TStr GetReference()
Definition: xml.cpp:340
Definition: dt.h:201
uchar Ch
Definition: xml.h:104
void TXmlLx::GetCDSect ( )
private

Definition at line 733 of file xml.cpp.

733  {
734  // [18] CDSect ::= CDStart CData CDEnd
735  // [19] CDStart ::= '<![CDATA{{['}}
736  // [20] CData ::= (Char* - (Char* ']]>' Char*))
737  // [21] CDEnd ::= ']]>'
738  if (Ch=='['){GetCh();}
739  else {EThrow("Invalid start of CDATA section.");}
740  TxtChA.Clr();
741  forever {
742  if (!ChDef.IsChar(Ch)){EThrow("Invalid CDATA character.");}
743  if ((Ch=='>')&&(TxtChA.Len()>=2)&&
744  (TxtChA.LastLastCh()==']') && (TxtChA.LastCh()==']')){
745  GetCh(); TxtChA.Pop(); TxtChA.Pop(); break;
746  } else {
747  TxtChA+=Ch; GetCh();
748  }
749  }
750 }
bool IsChar(const uchar &Ch) const
Definition: xml.h:68
TChA TxtChA
Definition: xml.h:140
#define forever
Definition: bd.h:6
void Clr()
Definition: dt.h:258
int Len() const
Definition: dt.h:259
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
char LastLastCh() const
Definition: dt.h:282
uchar GetCh()
Definition: xml.cpp:260
char LastCh() const
Definition: dt.h:281
char Pop()
Definition: dt.h:265
uchar Ch
Definition: xml.h:104
uchar TXmlLx::GetCh ( )
private

Definition at line 260 of file xml.cpp.

260  {
262  PrevCh=Ch;
263  if (ChStack.Empty()){Ch=(RSIn.Eof()) ? TCh::EofCh : RSIn.GetCh();}
264  else {Ch=ChStack.Pop();}
265  ChN++; if (Ch==TCh::LfCh){LnN++; LnChN=0;} else {LnChN++;}
266  //putchar(Ch);
267  return Ch;
268 }
bool Empty() const
Definition: dt.h:260
TChA ChStack
Definition: xml.h:103
uchar PrevCh
Definition: xml.h:104
static const char EofCh
Definition: dt.h:1040
TSIn & RSIn
Definition: xml.h:102
virtual bool Eof()=0
int LnChN
Definition: xml.h:105
static const char LfCh
Definition: dt.h:1038
#define EAssert(Cond)
Definition: bd.h:280
int LnN
Definition: xml.h:105
virtual char GetCh()=0
int ChN
Definition: xml.h:105
char Pop()
Definition: dt.h:265
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetChRefFromYuEntRef ( const TStr YuEntRefStr)
static

Definition at line 1072 of file xml.cpp.

1072  {
1073  TStr ChRefStr=YuEntRefStr;
1074  ChRefStr.ChangeStrAll("&ch;", "&#232;");
1075  ChRefStr.ChangeStrAll("&Ch;", "&#200;");
1076  ChRefStr.ChangeStrAll("&sh;", "&#154;");
1077  ChRefStr.ChangeStrAll("&Sh;", "&#138;");
1078  ChRefStr.ChangeStrAll("&zh;", "&#158;");
1079  ChRefStr.ChangeStrAll("&Zh;", "&#142;");
1080  ChRefStr.ChangeStrAll("&cs", "c");
1081  ChRefStr.ChangeStrAll("&Cs;", "C");
1082  ChRefStr.ChangeStrAll("&dz;", "dz");
1083  ChRefStr.ChangeStrAll("&Dz;", "Dz");
1084  return ChRefStr;
1085 }
int ChangeStrAll(const TStr &SrcStr, const TStr &DstStr, const bool &FromStartP=false)
Definition: dt.cpp:1141
Definition: dt.h:412
void TXmlLx::GetComment ( )
private

Definition at line 436 of file xml.cpp.

436  {
437  // [15] Comment ::= {{'<!-}}-' ((Char - '-') | ('-' (Char - '-')))* '-->'
438  if (GetCh()!='-'){EThrow("Invalid comment start.");}
439  TxtChA.Clr();
440  forever {
441  GetCh();
442  if (!ChDef.IsChar(Ch)){EThrow("Invalid comment character.");}
443  if (Ch=='-'){
444  if (GetCh()=='-'){
445  if (GetCh()=='>'){GetCh(); break;} // final bracket
446  else {EThrow("Invalid comment end.");}
447  } else {
448  if (!ChDef.IsChar(Ch)){EThrow("Invalid comment character.");}
449  TxtChA+='-'; TxtChA+=Ch; // special case if single '-'
450  }
451  } else {
452  TxtChA+=Ch; // usual char
453  }
454  }
455 }
bool IsChar(const uchar &Ch) const
Definition: xml.h:68
TChA TxtChA
Definition: xml.h:140
#define forever
Definition: bd.h:6
void Clr()
Definition: dt.h:258
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
uchar Ch
Definition: xml.h:104
void TXmlLx::GetDocTypeDecl ( )
private

Definition at line 627 of file xml.cpp.

627  {
628  // [28] doctypedecl ::= {{'<!DOCTYPE'}} S Name (S ExternalID)? S?
629  // ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
630  GetWs(true);
631  TStr DocTypeDeclNm=GetName();
632  GetWs(false);
633  if (Ch=='>'){GetCh(); return;}
634  if (Ch!='['){GetExternalId();}
635  GetWs(false);
636  if (Ch=='['){
637  GetCh();
638  // [28] (markupdecl | PEReference | S)*
639  GetWs(false);
640  while (Ch!=']'){
641  if (ChDef.IsWs(Ch)){GetWs(true);}
642  else if (Ch=='%'){GetPEReference();}
643  else {
644  GetSym();
645  }
646  }
647  GetCh();
648  }
649  GetWs(false);
650  // '>'
651  if (Ch=='>'){GetCh();}
652  else {EThrow("Invalid end-of-tag in document-type-declaration.");}
653  TagNm=DocTypeDeclNm;
654 }
TXmlLxSym GetSym()
Definition: xml.cpp:757
TStr TagNm
Definition: xml.h:141
TStr GetName()
Definition: xml.cpp:416
void GetWs(const bool &IsRq)
Definition: xml.cpp:331
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
void GetExternalId()
Definition: xml.cpp:609
Definition: dt.h:412
TStr GetPEReference()
Definition: xml.cpp:397
bool IsWs(const uchar &Ch) const
Definition: xml.h:76
uchar Ch
Definition: xml.h:104
void TXmlLx::GetElement ( )
private

Definition at line 656 of file xml.cpp.

656  {
657  TxtChA.Clr();
658  while (Ch!='>'){
659  if (!ChDef.IsChar(Ch)){EThrow("Invalid Element character.");}
660  TxtChA+=Ch; GetCh();
661  }
662  GetCh();
663 }
bool IsChar(const uchar &Ch) const
Definition: xml.h:68
TChA TxtChA
Definition: xml.h:140
void Clr()
Definition: dt.h:258
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetEncName ( )
private

Definition at line 493 of file xml.cpp.

493  {
494  // [80] EncodingDecl ::= {{S 'encoding' Eq}} ('"' EncName '"' | "'" EncName "'" )
495  // [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
496  char QCh=Ch;
497  if ((Ch!='\'')&&(Ch!='"')){EThrow("Quote character (' or \") expected.");}
498  TChA EncNmChA;
499  GetCh();
500  if ((('a'<=Ch)&&(Ch<='z'))||(('A'<=Ch)&&(Ch<='Z'))){EncNmChA+=Ch;}
501  else {EThrow("Invalid encoding-name character.");}
502  GetCh();
503  while (Ch!=QCh){
504  if ((('a'<=Ch)&&(Ch<='z'))||(('A'<=Ch)&&(Ch<='Z'))||
505  (('0'<=Ch)&&(Ch<='9'))||(Ch=='.')||(Ch=='_')||(Ch=='-')){EncNmChA+=Ch;}
506  else {EThrow("Invalid version-number character.");}
507  GetCh();
508  }
509  GetCh();
510  return EncNmChA;
511 }
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
Definition: dt.h:201
uchar Ch
Definition: xml.h:104
void TXmlLx::GetEntity ( )
private

Definition at line 690 of file xml.cpp.

690  {
691  // [70] EntityDecl ::= GEDecl | PEDecl
692  // [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
693  // [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
694  GetWs(true); TStr EntityNm;
695  if (Ch=='%'){
696  GetCh(); GetWs(true); EntityNm=GetName(); GetWs(true);
697  // [74] PEDef ::= EntityValue | ExternalID
698  if ((Ch=='\"')||(Ch=='\'')){
699  TStr EntityVal=GetEntityValue();
700  PutPEntityVal(EntityNm, EntityVal);
701  } else {
702  GetExternalId();
703  GetWs(false);
704  if (Ch!='>'){GetNData();}
705  }
706  } else {
707  EntityNm=GetName(); GetWs(true);
708  // [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?)
709  if ((Ch=='\"')||(Ch=='\'')){
710  TStr EntityVal=GetEntityValue();
711  PutEntityVal(EntityNm, EntityVal);
712  } else {
713  GetExternalId();
714  }
715  }
716  GetWs(false);
717  if (Ch=='>'){GetCh();}
718  else {EThrow("Invalid end-of-tag in entity-declaration.");}
719  TagNm=EntityNm;
720 }
TStr TagNm
Definition: xml.h:141
void GetNData()
Definition: xml.cpp:622
TStr GetName()
Definition: xml.cpp:416
void GetWs(const bool &IsRq)
Definition: xml.cpp:331
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
void PutEntityVal(const TStr &Nm, const TStr &Val)
Definition: xml.h:177
uchar GetCh()
Definition: xml.cpp:260
void GetExternalId()
Definition: xml.cpp:609
void PutPEntityVal(const TStr &Nm, const TStr &Val)
Definition: xml.h:181
Definition: dt.h:412
uchar Ch
Definition: xml.h:104
TStr GetEntityValue()
Definition: xml.cpp:674
TStr TXmlLx::GetEntityValue ( )
private

Definition at line 674 of file xml.cpp.

674  {
675  // [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
676  // | "'" ([^%&'] | PEReference | Reference)* "'"
677  uchar QCh=Ch;
678  if ((QCh!='"')&&(QCh!='\'')){EThrow("Invalid entity-value start.");}
679  TChA ValChA; GetCh();
680  forever {
681  if (!ChDef.IsChar(Ch)){EThrow("Invalid entity-value character.");}
682  if (Ch==QCh){GetCh(); break;} // final quote
683  else if (Ch=='&'){GetCh(); ValChA+=GetReference();} // reference
684  else if (Ch=='%'){GetCh(); ValChA+=GetPEReference();} // pereference
685  else {ValChA+=Ch; GetCh();} // usual char
686  }
687  return ValChA;
688 }
bool IsChar(const uchar &Ch) const
Definition: xml.h:68
#define forever
Definition: bd.h:6
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
unsigned char uchar
Definition: bd.h:10
TStr GetReference()
Definition: xml.cpp:340
Definition: dt.h:201
TStr GetPEReference()
Definition: xml.cpp:397
uchar Ch
Definition: xml.h:104
void TXmlLx::GetEq ( )
private

Definition at line 408 of file xml.cpp.

408  {
409  // [25] Eq ::= S? '=' S?
410  GetWs(false);
411  if (Ch=='='){GetCh();}
412  else {EThrow("Equality ('=') character expected.");}
413  GetWs(false);
414 }
void GetWs(const bool &IsRq)
Definition: xml.cpp:331
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
uchar Ch
Definition: xml.h:104
void TXmlLx::GetExternalId ( )
private

Definition at line 609 of file xml.cpp.

609  {
610  // ExternalID ::= 'SYSTEM' S SystemLiteral
611  // | 'PUBLIC' S PubidLiteral S SystemLiteral
612  TStr ExtIdNm=GetName();
613  if (ExtIdNm=="SYSTEM"){
614  GetWs(true); GetSystemLiteral();
615  } else if (ExtIdNm=="PUBLIC"){
616  GetWs(true); GetPubidLiteral(); GetWs(true); GetSystemLiteral();
617  } else {
618  EThrow("Invalid external-id ('SYSTEM' or 'PUBLIC' expected).");
619  }
620 }
TStr GetName()
Definition: xml.cpp:416
void GetWs(const bool &IsRq)
Definition: xml.cpp:331
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
Definition: dt.h:412
TStr GetSystemLiteral()
Definition: xml.cpp:583
TStr GetPubidLiteral()
Definition: xml.cpp:596
TStr TXmlLx::GetFPosStr ( ) const

Definition at line 895 of file xml.cpp.

895  {
896  TChA FPosChA;
897  FPosChA+=" [File:"; FPosChA+=SIn->GetSNm();
898  FPosChA+=" Line:"; FPosChA+=TInt::GetStr(LnN);
899  FPosChA+=" Char:"; FPosChA+=TInt::GetStr(LnChN);
900  FPosChA+="]";
901  return FPosChA;
902 }
TStr GetStr() const
Definition: dt.h:1200
PSIn SIn
Definition: xml.h:101
int LnChN
Definition: xml.h:105
Definition: dt.h:201
virtual TStr GetSNm() const
Definition: fl.cpp:20
int LnN
Definition: xml.h:105
TStr TXmlLx::GetName ( )
private

Definition at line 416 of file xml.cpp.

416  {
417  // [5] Name ::= (Letter | '_' | ':') (NameChar)*
418  TChA NmChA;
419  if (ChDef.IsFirstNameCh(Ch)){
420  do {NmChA+=Ch;} while (ChDef.IsName(GetCh()));
421  } else {
422  EThrow("Invalid first name character.");
423  // EThrow(TStr::Fmt("Invalid first name character [%u:'%c%c%c%c%c'].",
424  // uint(Ch), Ch, RSIn.GetCh(), RSIn.GetCh(), RSIn.GetCh(), RSIn.GetCh()));
425  }
426  return NmChA;
427 }
bool IsFirstNameCh(const uchar &Ch) const
Definition: xml.h:78
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
Definition: dt.h:201
bool IsName(const uchar &Ch) const
Definition: xml.h:73
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetName ( const TStr RqNm)
private

Definition at line 429 of file xml.cpp.

429  {
430  TStr Nm=GetName();
431  // test if the name is equal to the required name
432  if (Nm==RqNm){return RqNm;}
433  else {EThrow(TStr("Name '")+RqNm+"' expected."); Fail; return TStr();}
434 }
#define Fail
Definition: bd.h:238
TStr GetName()
Definition: xml.cpp:416
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
Definition: dt.h:412
void TXmlLx::GetNData ( )
private

Definition at line 622 of file xml.cpp.

622  {
623  // [76] NDataDecl ::= S 'NDATA' S Name
624  GetName("NDATA"); GetWs(true); GetName();
625 }
TStr GetName()
Definition: xml.cpp:416
void GetWs(const bool &IsRq)
Definition: xml.cpp:331
void TXmlLx::GetNotation ( )
private

Definition at line 722 of file xml.cpp.

722  {
723  // [82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'
724  // [83] PublicID ::= 'PUBLIC' S PubidLiteral
725  TxtChA.Clr();
726  while (Ch!='>'){
727  if (!ChDef.IsChar(Ch)){EThrow("Invalid Element character.");}
728  TxtChA+=Ch; GetCh();
729  }
730  GetCh();
731 }
bool IsChar(const uchar &Ch) const
Definition: xml.h:68
TChA TxtChA
Definition: xml.h:140
void Clr()
Definition: dt.h:258
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetPEReference ( )
private

Definition at line 397 of file xml.cpp.

397  {
398  // [69] PEReference ::= '%' Name ';'
399  TStr EntityNm=GetName();
400  if ((EntityNm.Empty())||(Ch!=';')){EThrow("Invalid PEntity-Reference.");}
401  GetCh();
402  TStr EntityVal;
403  if (IsPEntityNm(EntityNm, EntityVal)){/*intentionaly empty*/}
404  else {EThrow(TStr("PEntity-Reference (")+EntityNm+") does not exist.");}
405  return EntityVal;
406 }
bool IsPEntityNm(const TStr &EntityNm, TStr &EntityVal) const
Definition: xml.h:179
TStr GetName()
Definition: xml.cpp:416
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
Definition: dt.h:412
bool Empty() const
Definition: dt.h:491
uchar Ch
Definition: xml.h:104
void TXmlLx::GetPI ( )
private

Definition at line 562 of file xml.cpp.

562  {
563  // [16] PI ::= {{'<?' PITarget}} (S (Char* - (Char* '?>' Char*)))? '?>'
564  // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
565  GetWs(false);
566  TxtChA.Clr();
567  forever {
568  if (!ChDef.IsChar(Ch)){EThrow("Invalid PI character.");}
569  if (Ch=='?'){
570  if (GetCh()=='>'){
571  GetCh(); break;
572  } else {
573  if (!ChDef.IsChar(Ch)){EThrow("Invalid PI character.");}
574  TxtChA+='?'; TxtChA+=Ch; // special case if single '?'
575  }
576  } else {
577  TxtChA+=Ch; // usual char
578  }
579  GetCh();
580  }
581 }
bool IsChar(const uchar &Ch) const
Definition: xml.h:68
TChA TxtChA
Definition: xml.h:140
#define forever
Definition: bd.h:6
void Clr()
Definition: dt.h:258
void GetWs(const bool &IsRq)
Definition: xml.cpp:331
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetPlainStrFromXmlStr ( const TStr XmlStr)
static

Definition at line 991 of file xml.cpp.

991  {
992  TChA PlainChA;
993  TChRet Ch(TStrIn::New(XmlStr));
994  Ch.GetCh();
995  while (!Ch.Eof()){
996  if (Ch()!='&'){
997  PlainChA+=Ch(); Ch.GetCh();
998  } else {
999  // [67] Reference ::= EntityRef | CharRef
1000  if (Ch.GetCh()=='#'){
1001  // [66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'
1002  TChA RefChA; int RefCd=0;
1003  if (Ch.GetCh()=='x'){
1004  // hex-decimal character code
1005  forever {
1006  Ch.GetCh();
1007  if (TCh::IsHex(Ch())){
1008  RefChA+=Ch();
1009  RefCd=RefCd*16+TCh::GetHex(Ch());
1010  } else {
1011  break;
1012  }
1013  }
1014  } else {
1015  // decimal character code
1016  forever {
1017  if (TCh::IsNum(Ch())){
1018  RefChA+=Ch();
1019  RefCd=RefCd*10+TCh::GetNum(Ch());
1020  } else {
1021  break;
1022  }
1023  Ch.GetCh();
1024  }
1025  }
1026  if ((!RefChA.Empty())&&(Ch()==';')){
1027  Ch.GetCh();
1028  if (RefCd < 0x80) {
1029  // ascii character
1030  uchar RefCh=uchar(RefCd);
1031  PlainChA+=RefCh;
1032  } else {
1033  // unicode
1034  TUnicode::EncodeUtf8(RefCd, PlainChA);
1035  }
1036  }
1037  } else {
1038  // [68] EntityRef ::= '&' Name ';'
1039  TChA EntityNm;
1040  while ((!Ch.Eof())&&(Ch()!=';')){
1041  EntityNm+=Ch(); Ch.GetCh();}
1042  if ((!EntityNm.Empty())&&(Ch()==';')){
1043  Ch.GetCh();
1044  if (EntityNm=="quot"){PlainChA+='"';}
1045  else if (EntityNm=="amp"){PlainChA+='&';}
1046  else if (EntityNm=="apos"){PlainChA+='\'';}
1047  else if (EntityNm=="lt"){PlainChA+='<';}
1048  else if (EntityNm=="gt"){PlainChA+='>';}
1049  }
1050  }
1051  }
1052  }
1053  return PlainChA;
1054 }
static bool IsHex(const char &Ch)
Definition: dt.h:1070
static bool IsNum(const char &Ch)
Definition: dt.h:1067
#define forever
Definition: bd.h:6
bool Empty() const
Definition: dt.h:260
static int GetHex(const char &Ch)
Definition: dt.h:1072
static PSIn New(const TStr &Str)
Definition: dt.h:711
static int GetNum(const char &Ch)
Definition: dt.h:1069
unsigned char uchar
Definition: bd.h:10
Definition: dt.h:201
int EncodeUtf8(const TIntV &src, TIntV &dest) const
Definition: unicode.h:1792
uchar Ch
Definition: xml.h:104
Definition: fl.h:535
TStr TXmlLx::GetPubidLiteral ( )
private

Definition at line 596 of file xml.cpp.

596  {
597  // [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
598  char QCh=Ch;
599  if ((Ch!='\'')&&(Ch!='"')){EThrow("Quote character (' or \") expected.");}
600  TChA LitChA; GetCh();
601  while (Ch!=QCh){
602  if (!ChDef.IsPubid(Ch)){EThrow("Invalid Public-Id-Literal character.");}
603  LitChA+=Ch; GetCh();
604  }
605  GetCh();
606  return LitChA;
607 }
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
bool IsPubid(const uchar &Ch) const
Definition: xml.h:74
Definition: dt.h:201
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetReference ( )
private

Definition at line 340 of file xml.cpp.

340  {
341  // [67] Reference ::= EntityRef | CharRef
342  if (Ch=='#'){
343  // [66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'
344  TChA RefChA; int RefCd=0;
345  if (GetCh()=='x'){
346  // hex-decimal character code
347  forever {
348  GetCh();
349  if (TCh::IsHex(Ch)){
350  RefChA+=Ch;
351  RefCd=RefCd*16+TCh::GetHex(Ch);
352  } else {
353  break;
354  }
355  }
356  } else {
357  // decimal character code
358  forever {
359  if (TCh::IsNum(Ch)){
360  RefChA+=Ch;
361  RefCd=RefCd*10+TCh::GetNum(Ch);
362  } else {
363  break;
364  }
365  GetCh();
366  }
367  }
368  if ((!RefChA.Empty())&&(Ch==';')){
369  GetCh();
370  if (RefCd < 0x80) {
371  // 8-bit char
372  uchar RefCh=uchar(RefCd);
373  return TStr(RefCh);
374  } else {
375  TStr ResStr = TUnicode::EncodeUtf8(RefCd);
376  return ResStr;
377  }
378  } else {
379  EThrow("Invalid Char-Reference."); Fail; return TStr();
380  }
381  } else {
382  // [68] EntityRef ::= '&' Name ';'
383  TStr EntityNm=GetName();
384  if ((!EntityNm.Empty())&&(Ch==';')){
385  GetCh();
386  TStr EntityVal;
387  if (IsEntityNm(EntityNm, EntityVal)){/*intentionaly empty*/}
388  else if (ChDef.IsEntityNm(EntityNm, EntityVal)){/*intentionaly empty*/}
389  else {EThrow(TStr("Entity-Reference (")+EntityNm+") does not exist.");}
390  return EntityVal;
391  } else {
392  EThrow("Invalid Entity-Reference."); Fail; return TStr();
393  }
394  }
395 }
static bool IsHex(const char &Ch)
Definition: dt.h:1070
static bool IsNum(const char &Ch)
Definition: dt.h:1067
#define forever
Definition: bd.h:6
bool Empty() const
Definition: dt.h:260
#define Fail
Definition: bd.h:238
TStr GetName()
Definition: xml.cpp:416
static int GetHex(const char &Ch)
Definition: dt.h:1072
bool IsEntityNm(const TStr &EntityNm, TStr &EntityVal) const
Definition: xml.h:83
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
static int GetNum(const char &Ch)
Definition: dt.h:1069
unsigned char uchar
Definition: bd.h:10
Definition: dt.h:201
Definition: dt.h:412
bool Empty() const
Definition: dt.h:491
bool IsEntityNm(const TStr &EntityNm, TStr &EntityVal) const
Definition: xml.h:175
int EncodeUtf8(const TIntV &src, TIntV &dest) const
Definition: unicode.h:1792
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetStalVal ( )
private

Definition at line 513 of file xml.cpp.

513  {
514  // [32] SDDecl ::= {{S 'standalone' Eq}}
515  // (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
516  char QCh=Ch;
517  if ((Ch!='\'')&&(Ch!='"')){EThrow("Quote character (' or \") expected.");}
518  TChA StalChA;
519  GetCh();
520  while (Ch!=QCh){
521  if (('a'<=Ch)&&(Ch<='z')){StalChA+=Ch;}
522  else {EThrow("Invalid standalone-value character.");}
523  GetCh();
524  }
525  GetCh();
526  TStr StalVal=StalChA;
527  if ((StalVal=="yes")||(StalVal=="no")){return StalVal;}
528  else {EThrow("Invalid standalone-value."); Fail; return TStr();}
529 }
#define Fail
Definition: bd.h:238
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
Definition: dt.h:201
Definition: dt.h:412
uchar Ch
Definition: xml.h:104
TXmlLxSym TXmlLx::GetSym ( )

Definition at line 757 of file xml.cpp.

757  {
758  if (Ch=='<'){
759  GetCh(); ClrArgV();
760  if (Ch=='?'){
761  GetCh(); TagNm=GetName();
762  if (TagNm.GetLc()=="xml"){Sym=xsyXmlDecl; GetXmlDecl();}
763  else {Sym=xsyPI; GetPI();}
764  } else
765  if (Ch=='!'){
766  GetCh();
767  if (Ch=='['){
768  GetCh(); TagNm=GetName();
769  if (TagNm=="CDATA"){Sym=xsyQStr; GetCDSect();}
770  else {EThrow(TStr("Invalid tag after '<![' (")+TagNm+").");}
771  } else
772  if (Ch=='-'){
774  } else {
775  TagNm=GetName();
776  if (TagNm=="DOCTYPE"){GetDocTypeDecl(); Sym=xsyDocTypeDecl;}
777  else if (TagNm=="ELEMENT"){GetElement(); Sym=xsyElement;}
778  else if (TagNm=="ATTLIST"){GetAttList(); Sym=xsyAttList;}
779  else if (TagNm=="ENTITY"){GetEntity(); Sym=xsyEntity;}
780  else if (TagNm=="NOTATION"){GetNotation(); Sym=xsyNotation;}
781  else {EThrow(TStr("Invalid tag (")+TagNm+").");}
782  }
783  } else
784  if (Ch=='/'){
785  // xsyETag
786  GetCh(); Sym=xsyETag; TagNm=GetName(); GetWs(false);
787  if (Ch=='>'){GetCh();}
788  else {EThrow("Invalid End-Tag.");}
789  } else {
790  // xsySTag or xsySETag
791  TagNm=GetName(); GetWs(false);
792  while ((Ch!='>')&&(Ch!='/')){
793  TStr AttrNm=GetName();
794  GetEq();
795  TStr AttrVal=GetAttValue();
796  GetWs(false);
797  AddArg(AttrNm, AttrVal);
798  }
799  if (Ch=='/'){
800  if (GetCh()=='>'){Sym=xsySETag; GetCh();}
801  else {EThrow("Invalid Empty-Element-Tag.");}
802  } else {
803  Sym=xsySTag; GetCh();
804  }
805  }
806  if (Spacing==xspTruncate){SkipWs();}
807  } else
808  if (ChDef.IsWs(Ch)){
809  Sym=xsyWs; GetWs(true); ToNrSpacing();
810  if (Spacing==xspTruncate){GetSym();}
811  } else
812  if (Ch==TCh::EofCh){
813  Sym=xsyEof;
814  } else {
815  Sym=xsyStr; TxtChA.Clr();
816  // [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
817  forever {
818  if (!ChDef.IsChar(Ch)){
819  EThrow(TUInt::GetStr(Ch, "Invalid character (%d)."));}
820  // GetCh(); continue; // skip invalid characters
821  if (Ch=='<'){break;} // tag
822  if (Ch=='&'){GetCh(); TxtChA+=GetReference();} // reference
823  else {
824  if ((Ch=='>')&&(TxtChA.Len()>=2)&&
825  (TxtChA.LastLastCh()==']')&&(TxtChA.LastCh()==']')){
826  EThrow("Forbidden substring ']]>' in character data.");}
827  TxtChA+=Ch; GetCh(); // usual char
828  }
829  }
830  ToNrSpacing();
831  }
832  return Sym;
833 }
TXmlLxSym GetSym()
Definition: xml.cpp:757
TStr TagNm
Definition: xml.h:141
bool IsChar(const uchar &Ch) const
Definition: xml.h:68
void GetXmlDecl()
Definition: xml.cpp:531
TChA TxtChA
Definition: xml.h:140
Definition: xml.h:93
void GetEntity()
Definition: xml.cpp:690
Definition: xml.h:91
Definition: xml.h:94
void AddArg(const TStr &ArgNm, const TStr &ArgVal)
Definition: xml.h:161
#define forever
Definition: bd.h:6
void GetEq()
Definition: xml.cpp:408
TStr GetName()
Definition: xml.cpp:416
void Clr()
Definition: dt.h:258
void GetWs(const bool &IsRq)
Definition: xml.cpp:331
Definition: xml.h:90
int Len() const
Definition: dt.h:259
static TXmlChDef ChDef
Definition: xml.h:100
void GetAttList()
Definition: xml.cpp:665
void GetPI()
Definition: xml.cpp:562
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
void ToNrSpacing()
Definition: xml.cpp:270
char LastLastCh() const
Definition: dt.h:282
static const char EofCh
Definition: dt.h:1040
uchar GetCh()
Definition: xml.cpp:260
Definition: xml.h:93
TStr GetStr() const
Definition: dt.h:1282
char LastCh() const
Definition: dt.h:281
Definition: xml.h:92
TStr GetLc() const
Definition: dt.h:502
Definition: xml.h:93
Definition: xml.h:93
TStr GetReference()
Definition: xml.cpp:340
Definition: xml.h:93
void GetNotation()
Definition: xml.cpp:722
Definition: dt.h:412
Definition: xml.h:92
void GetCDSect()
Definition: xml.cpp:733
TXmlSpacing Spacing
Definition: xml.h:106
Definition: xml.h:92
TStr GetAttValue()
Definition: xml.cpp:457
void GetElement()
Definition: xml.cpp:656
void ClrArgV()
Definition: xml.h:160
Definition: xml.h:90
void SkipWs()
Definition: xml.cpp:752
TXmlLxSym Sym
Definition: xml.h:139
void GetDocTypeDecl()
Definition: xml.cpp:627
void GetComment()
Definition: xml.cpp:436
bool IsWs(const uchar &Ch) const
Definition: xml.h:76
uchar Ch
Definition: xml.h:104
Definition: xml.h:91
TStr TXmlLx::GetSymStr ( ) const

Definition at line 835 of file xml.cpp.

835  {
836  TChA SymChA;
837  switch (Sym){
838  case xsyUndef:
839  SymChA="{Undef}"; break;
840  case xsyWs:
841  SymChA+="{Space:'"; SymChA+=TStr(TxtChA).GetHex(); SymChA+="'}"; break;
842  case xsyComment:
843  SymChA+="<!--"; SymChA+=TxtChA; SymChA+="-->"; break;
844  case xsyXmlDecl:{
845  SymChA+="<?"; SymChA+=TagNm;
846  for (int ArgN=0; ArgN<GetArgs(); ArgN++){
847  TStr ArgNm; TStr ArgVal; GetArg(ArgN, ArgNm, ArgVal);
848  char ArgValQCh=GetArgValQCh(ArgVal);
849  SymChA+=' '; SymChA+=ArgNm; SymChA+='=';
850  SymChA+=ArgValQCh; SymChA+=ArgVal; SymChA+=ArgValQCh;
851  }
852  SymChA+="?>"; break;}
853  case xsyPI:
854  SymChA+="<?"; SymChA+=TagNm;
855  if (!TxtChA.Empty()){SymChA+=' '; SymChA+=TxtChA;}
856  SymChA+="?>"; break;
857  case xsyDocTypeDecl:
858  SymChA+="<!DOCTYPE "; SymChA+=TagNm; SymChA+=">"; break;
859  case xsySTag:
860  case xsySETag:{
861  SymChA+="<"; SymChA+=TagNm;
862  for (int ArgN=0; ArgN<GetArgs(); ArgN++){
863  TStr ArgNm; TStr ArgVal; GetArg(ArgN, ArgNm, ArgVal);
864  char ArgValQCh=GetArgValQCh(ArgVal);
865  SymChA+=' '; SymChA+=ArgNm; SymChA+='=';
866  SymChA+=ArgValQCh; SymChA+=ArgVal; SymChA+=ArgValQCh;
867  }
868  if (Sym==xsySTag){SymChA+=">";}
869  else if (Sym==xsySETag){SymChA+="/>";}
870  else {Fail;}
871  break;}
872  case xsyETag:
873  SymChA+="</"; SymChA+=TagNm; SymChA+=">"; break;
874  case xsyStr:
875  SymChA="{String:'"; SymChA+=TxtChA; SymChA+="'}"; break;
876  case xsyQStr:
877  SymChA="{QString:'"; SymChA+=TxtChA; SymChA+="'}"; break;
878  case xsyEof:
879  SymChA="{Eof}"; break;
880  default: Fail;
881  }
882  return SymChA;
883 }
TStr TagNm
Definition: xml.h:141
TChA TxtChA
Definition: xml.h:140
Definition: xml.h:93
Definition: xml.h:91
void GetArg(const int &ArgN, TStr &ArgNm, TStr &ArgVal) const
Definition: xml.h:166
Definition: xml.h:94
bool Empty() const
Definition: dt.h:260
#define Fail
Definition: bd.h:238
Definition: xml.h:90
Definition: xml.h:93
Definition: xml.h:93
static char GetArgValQCh(const TStr &ArgVal)
Definition: xml.h:171
Definition: xml.h:90
Definition: xml.h:93
int GetArgs() const
Definition: xml.h:165
Definition: xml.h:93
Definition: dt.h:201
Definition: dt.h:412
TStr GetHex() const
Definition: dt.h:515
Definition: xml.h:90
TXmlLxSym Sym
Definition: xml.h:139
Definition: xml.h:91
TStr TXmlLx::GetSystemLiteral ( )
private

Definition at line 583 of file xml.cpp.

583  {
584  // [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
585  char QCh=Ch;
586  if ((Ch!='\'')&&(Ch!='"')){EThrow("Quote character (' or \") expected.");}
587  TChA LitChA; GetCh();
588  while (Ch!=QCh){
589  if (!ChDef.IsChar(Ch)){EThrow("Invalid System-Literal character.");}
590  LitChA+=Ch; GetCh();
591  }
592  GetCh();
593  return LitChA;
594 }
bool IsChar(const uchar &Ch) const
Definition: xml.h:68
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
Definition: dt.h:201
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetUsAsciiStrFromXmlStr ( const TStr EntRefStr)
static

Definition at line 1056 of file xml.cpp.

1056  {
1057  TStr UsAsciiStr=XmlStr;
1058  UsAsciiStr.ChangeStrAll("&#232;", "c");
1059  UsAsciiStr.ChangeStrAll("&#200;", "C");
1060  UsAsciiStr.ChangeStrAll("&#154;", "s");
1061  UsAsciiStr.ChangeStrAll("&#138;", "S");
1062  UsAsciiStr.ChangeStrAll("&#158;", "z");
1063  UsAsciiStr.ChangeStrAll("&#142;", "Z");
1064  TChA UsAsciiChA=TXmlLx::GetPlainStrFromXmlStr(UsAsciiStr);
1065  for (int ChN=0; ChN<UsAsciiChA.Len(); ChN++){
1066  char Ch=UsAsciiChA[ChN];
1067  if ((Ch<' ')||('~'<Ch)){UsAsciiChA.PutCh(ChN, 'x');}
1068  }
1069  return UsAsciiChA;
1070 }
void PutCh(const int &ChN, const char &Ch)
Definition: dt.h:278
static TStr GetPlainStrFromXmlStr(const TStr &XmlStr)
Definition: xml.cpp:991
int Len() const
Definition: dt.h:259
int ChangeStrAll(const TStr &SrcStr, const TStr &DstStr, const bool &FromStartP=false)
Definition: dt.cpp:1141
Definition: dt.h:201
Definition: dt.h:412
int ChN
Definition: xml.h:105
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetVersionNum ( )
private

Definition at line 473 of file xml.cpp.

473  {
474  // [24] VersionInfo ::= {{S 'version' Eq}} (' VersionNum ' | " VersionNum ")
475  // [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+
476  char QCh=Ch;
477  if ((Ch!='\'')&&(Ch!='"')){EThrow("Quote character (' or \") expected.");}
478  TChA VerNumChA;
479  GetCh();
480  do {
481  if ((('a'<=Ch)&&(Ch<='z'))||(('A'<=Ch)&&(Ch<='Z'))||
482  (('0'<=Ch)&&(Ch<='9'))||(Ch=='_')||(Ch=='.')||(Ch==':')||(Ch=='-')){
483  VerNumChA+=Ch;
484  } else {
485  EThrow("Invalid version-number character.");
486  }
487  GetCh();
488  } while (Ch!=QCh);
489  GetCh();
490  return VerNumChA;
491 }
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
Definition: dt.h:201
uchar Ch
Definition: xml.h:104
void TXmlLx::GetWs ( const bool &  IsRq)
private

Definition at line 331 of file xml.cpp.

331  {
332  // [3] S ::= (#x20 | #x9 | #xD | #xA)+
333  int WSpaces=0; TxtChA.Clr();
334  while (ChDef.IsWs(Ch)){
335  WSpaces++; TxtChA+=Ch; GetCh();}
336  if (IsRq&&(WSpaces==0)){
337  EThrow("White-space required.");}
338 }
TChA TxtChA
Definition: xml.h:140
void Clr()
Definition: dt.h:258
static TXmlChDef ChDef
Definition: xml.h:100
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
uchar GetCh()
Definition: xml.cpp:260
bool IsWs(const uchar &Ch) const
Definition: xml.h:76
uchar Ch
Definition: xml.h:104
void TXmlLx::GetXmlDecl ( )
private

Definition at line 531 of file xml.cpp.

531  {
532  // [23] XMLDecl ::= {{'<?xml'}}... VersionInfo EncodingDecl? SDDecl? S? '?>'
533  // [24] VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ")
534  GetWs(true);
535  TStr VerNm=GetName("version"); GetEq(); TStr VerVal=GetVersionNum();
536  if (VerVal!="1.0"){EThrow("Invalid XML version.");}
537  AddArg(VerNm, VerVal);
538  GetWs(false);
539  if (Ch!='?'){
540  // EncodingDecl ::= {{S}} 'encoding' Eq
541  // ('"' EncName '"' | "'" EncName "'" )
542  TStr EncNm=GetName("encoding"); GetEq(); TStr EncVal=GetEncName();
543  AddArg(EncNm, EncVal);
544  }
545  GetWs(false);
546  if (Ch!='?'){
547  // SDDecl ::= {{S}} 'standalone' Eq
548  // (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
549  TStr StalNm=GetName("standalone"); GetEq(); TStr StalVal=GetStalVal();
550  AddArg(StalNm, StalVal);
551  }
552  GetWs(false);
553  if (Ch=='?'){
554  GetCh();
555  if (Ch=='>'){GetCh();}
556  else {EThrow("Invalid end-of-tag in XML-declaration.");}
557  } else {
558  EThrow("Invalid end-of-tag in XML-declaration.");
559  }
560 }
void AddArg(const TStr &ArgNm, const TStr &ArgVal)
Definition: xml.h:161
void GetEq()
Definition: xml.cpp:408
TStr GetName()
Definition: xml.cpp:416
void GetWs(const bool &IsRq)
Definition: xml.cpp:331
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
TStr GetStalVal()
Definition: xml.cpp:513
uchar GetCh()
Definition: xml.cpp:260
TStr GetVersionNum()
Definition: xml.cpp:473
TStr GetEncName()
Definition: xml.cpp:493
Definition: dt.h:412
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetXmlLxSymStr ( const TXmlLxSym XmlLxSym)
static

Definition at line 904 of file xml.cpp.

904  {
905  switch (XmlLxSym){
906  case xsyUndef: return "Undef";
907  case xsyWs: return "White-Space";
908  case xsyComment: return "Comment";
909  case xsyXmlDecl: return "Declaration";
910  case xsyPI: return "PI";
911  case xsyDocTypeDecl: return "Document-Type";
912  case xsyElement: return "Element";
913  case xsyAttList: return "Attribute-List";
914  case xsyEntity: return "Entity";
915  case xsyNotation: return "Notation";
916  case xsyTag: return "Tag";
917  case xsySTag: return "Start-Tag";
918  case xsyETag: return "End-Tag";
919  case xsySETag: return "Start-End-Tag";
920  case xsyStr: return "String";
921  case xsyQStr: return "Quoted-String";
922  case xsyEof: return "Eon-Of-File";
923  default: return "Undef";
924  }
925 }
Definition: xml.h:93
Definition: xml.h:91
Definition: xml.h:93
Definition: xml.h:94
Definition: xml.h:90
Definition: xml.h:93
Definition: xml.h:92
Definition: xml.h:93
Definition: xml.h:90
Definition: xml.h:93
Definition: xml.h:93
Definition: xml.h:92
Definition: xml.h:92
Definition: xml.h:90
Definition: xml.h:91
TStr TXmlLx::GetXmlStrFromPlainMem ( const TMem PlainMem)
static

Definition at line 945 of file xml.cpp.

945  {
946  TChA XmlChA;
947  for (int ChN=0; ChN<PlainMem.Len(); ChN++){
948  uchar Ch=PlainMem[ChN];
949  if ((' '<=Ch)&&(Ch<='~')){
950  switch (Ch){
951  case '"': XmlChA+="&quot;"; break;
952  case '&': XmlChA+="&amp;"; break;
953  case '\'': XmlChA+="&apos;"; break;
954  case '<': XmlChA+="&lt;"; break;
955  case '>': XmlChA+="&gt;"; break;
956  default: XmlChA+=Ch;
957  }
958  } else
959  if ((Ch=='\r')||(Ch=='\n')){
960  XmlChA+=Ch;
961  } else {
962  XmlChA+='&'; XmlChA+='#'; XmlChA+=TUInt::GetStr(Ch); XmlChA+=';';
963  }
964  }
965  return XmlChA;
966 }
int Len() const
Definition: dt.h:134
TStr GetStr() const
Definition: dt.h:1282
unsigned char uchar
Definition: bd.h:10
Definition: dt.h:201
int ChN
Definition: xml.h:105
uchar Ch
Definition: xml.h:104
TStr TXmlLx::GetXmlStrFromPlainStr ( const TChA PlainChA)
static

Definition at line 968 of file xml.cpp.

968  {
969  TChA XmlChA;
970  for (int ChN=0; ChN<PlainChA.Len(); ChN++){
971  uchar Ch=PlainChA[ChN];
972  if ((' '<=Ch)&&(Ch<='~')){
973  switch (Ch){
974  case '"': XmlChA+="&quot;"; break;
975  case '&': XmlChA+="&amp;"; break;
976  case '\'': XmlChA+="&apos;"; break;
977  case '<': XmlChA+="&lt;"; break;
978  case '>': XmlChA+="&gt;"; break;
979  default: XmlChA+=Ch;
980  }
981  } else
982  if ((Ch=='\r')||(Ch=='\n')){
983  XmlChA+=Ch;
984  } else {
985  XmlChA+='&'; XmlChA+='#'; XmlChA+=TUInt::GetStr(Ch); XmlChA+=';';
986  }
987  }
988  return XmlChA;
989 }
int Len() const
Definition: dt.h:259
TStr GetStr() const
Definition: dt.h:1282
unsigned char uchar
Definition: bd.h:10
Definition: dt.h:201
int ChN
Definition: xml.h:105
uchar Ch
Definition: xml.h:104
bool TXmlLx::IsArgNm ( const TStr ArgNm) const
inline

Definition at line 163 of file xml.h.

163  {
164  return ArgNmValKdV.IsIn(TStrKd(ArgNm));}
bool IsIn(const TVal &Val) const
Checks whether element Val is a member of the vector.
Definition: ds.h:828
TStrKdV ArgNmValKdV
Definition: xml.h:142
TKeyDat< TStr, TStr > TStrKd
Definition: ds.h:405
bool TXmlLx::IsEntityNm ( const TStr EntityNm,
TStr EntityVal 
) const
inline

Definition at line 175 of file xml.h.

175  {
176  return EntityNmToValH.IsKeyGetDat(EntityNm, EntityVal);}
TStrStrH EntityNmToValH
Definition: xml.h:113
bool IsKeyGetDat(const TKey &Key, TDat &Dat) const
Definition: hash.h:274
bool TXmlLx::IsPEntityNm ( const TStr EntityNm,
TStr EntityVal 
) const
inline

Definition at line 179 of file xml.h.

179  {
180  return PEntityNmToValH.IsKeyGetDat(EntityNm, EntityVal);}
bool IsKeyGetDat(const TKey &Key, TDat &Dat) const
Definition: hash.h:274
TStrStrH PEntityNmToValH
Definition: xml.h:113
bool TXmlLx::IsTagNm ( const TStr Str)
static

Definition at line 927 of file xml.cpp.

927  {
928  TChA ChA=Str;
929  if (ChA.Len()>0){
930  if (TXmlLx::ChDef.IsFirstNameCh(ChA[0])){
931  for (int ChN=1; ChN<ChA.Len(); ChN++){
932  if (!TXmlLx::ChDef.IsName(ChA[ChN])){
933  return false;
934  }
935  }
936  return true;
937  } else {
938  return false;
939  }
940  } else {
941  return false;
942  }
943 }
int Len() const
Definition: dt.h:259
static TXmlChDef ChDef
Definition: xml.h:100
Definition: dt.h:201
int ChN
Definition: xml.h:105
TXmlLx& TXmlLx::operator= ( const TXmlLx )
inline

Definition at line 152 of file xml.h.

152 {Fail; return *this;}
#define Fail
Definition: bd.h:238
void TXmlLx::PutCh ( const uchar _Ch)
inlineprivate

Definition at line 108 of file xml.h.

108 {ChStack.Push(Ch); Ch=_Ch;}
TChA ChStack
Definition: xml.h:103
void Push(const char &Ch)
Definition: dt.h:264
uchar Ch
Definition: xml.h:104
void TXmlLx::PutEntityVal ( const TStr Nm,
const TStr Val 
)
inline

Definition at line 177 of file xml.h.

177  {
178  EntityNmToValH.AddDat(Nm, Val);}
TStrStrH EntityNmToValH
Definition: xml.h:113
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
void TXmlLx::PutPEntityVal ( const TStr Nm,
const TStr Val 
)
inline

Definition at line 181 of file xml.h.

181  {
182  PEntityNmToValH.AddDat(Nm, Val);}
TStrStrH PEntityNmToValH
Definition: xml.h:113
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
void TXmlLx::PutStr ( const TStr Str)
inlineprivate

Definition at line 109 of file xml.h.

109  {
110  for (int ChN=Str.Len()-1; ChN>=0; ChN--){PutCh(Str[ChN]);}}
int Len() const
Definition: dt.h:490
void PutCh(const uchar &_Ch)
Definition: xml.h:108
int ChN
Definition: xml.h:105
void TXmlLx::SkipWs ( )

Definition at line 752 of file xml.cpp.

752  {
753  // [3] S ::= (#x20 | #x9 | #xD | #xA)+
754  while (ChDef.IsWs(Ch)){GetCh();}
755 }
static TXmlChDef ChDef
Definition: xml.h:100
uchar GetCh()
Definition: xml.cpp:260
bool IsWs(const uchar &Ch) const
Definition: xml.h:76
uchar Ch
Definition: xml.h:104
void TXmlLx::ToNrSpacing ( )
private

Definition at line 270 of file xml.cpp.

270  {
271  if (Spacing==xspIntact){
272  } else
273  if (Spacing==xspPreserve){
274  int SrcChN=0; int DstChN=0;
275  while (SrcChN<TxtChA.Len()){
276  if (TxtChA[SrcChN]==TCh::CrCh){
277  TxtChA.PutCh(DstChN, TCh::LfCh); SrcChN++; DstChN++;
278  if ((SrcChN<TxtChA.Len())&&(TxtChA[SrcChN]==TCh::LfCh)){SrcChN++;}
279  } else {
280  if (SrcChN!=DstChN){
281  TxtChA.PutCh(DstChN, TxtChA[SrcChN]);}
282  SrcChN++; DstChN++;
283  }
284  }
285  TxtChA.Trunc(DstChN);
286  } else
287  if (Spacing==xspSeparate){
288  // squeeze series of white-spaces to single space
289  int SrcChN=0; int DstChN=0;
290  while (SrcChN<TxtChA.Len()){
291  if (ChDef.IsWs(TxtChA[SrcChN])){
292  if ((DstChN>0)&&(TxtChA[DstChN-1]==' ')){
293  SrcChN++;
294  } else {
295  TxtChA.PutCh(DstChN, ' ');
296  SrcChN++; DstChN++;
297  }
298  } else {
299  TxtChA.PutCh(DstChN, TxtChA[SrcChN]);
300  SrcChN++; DstChN++;
301  }
302  }
303  TxtChA.Trunc(DstChN);
304  } else
305  if (Spacing==xspTruncate){
306  // cut leading and trailing white-spaces and
307  // squeeze series of white-spaces to single space
308  int SrcChN=0; int DstChN=0;
309  while (SrcChN<TxtChA.Len()){
310  if (ChDef.IsWs(TxtChA[SrcChN])){
311  if ((DstChN>0)&&(TxtChA[DstChN-1]==' ')){
312  SrcChN++;
313  } else {
314  TxtChA.PutCh(DstChN, ' ');
315  SrcChN++; DstChN++;
316  }
317  } else {
318  TxtChA.PutCh(DstChN, TxtChA[SrcChN]);
319  SrcChN++; DstChN++;
320  }
321  }
322  TxtChA.Trunc(DstChN);
323  // delete trailing white-spaces
324  while ((TxtChA.Len()>0)&&(ChDef.IsWs(TxtChA.LastCh()))){
325  TxtChA.Pop();}
326  } else {
327  Fail;
328  }
329 }
TChA TxtChA
Definition: xml.h:140
#define Fail
Definition: bd.h:238
void PutCh(const int &ChN, const char &Ch)
Definition: dt.h:278
int Len() const
Definition: dt.h:259
static TXmlChDef ChDef
Definition: xml.h:100
Definition: xml.h:96
char LastCh() const
Definition: dt.h:281
void Trunc()
Definition: dt.cpp:420
static const char LfCh
Definition: dt.h:1038
TXmlSpacing Spacing
Definition: xml.h:106
static const char CrCh
Definition: dt.h:1039
char Pop()
Definition: dt.h:265
bool IsWs(const uchar &Ch) const
Definition: xml.h:76

Member Data Documentation

TStrKdV TXmlLx::ArgNmValKdV

Definition at line 142 of file xml.h.

uchar TXmlLx::Ch
private

Definition at line 104 of file xml.h.

TXmlChDef TXmlLx::ChDef
staticprivate

Definition at line 100 of file xml.h.

int TXmlLx::ChN
private

Definition at line 105 of file xml.h.

TChA TXmlLx::ChStack
private

Definition at line 103 of file xml.h.

TStrStrH TXmlLx::EntityNmToValH
private

Definition at line 113 of file xml.h.

int TXmlLx::LnChN
private

Definition at line 105 of file xml.h.

int TXmlLx::LnN
private

Definition at line 105 of file xml.h.

TStrStrH TXmlLx::PEntityNmToValH
private

Definition at line 113 of file xml.h.

uchar TXmlLx::PrevCh
private

Definition at line 104 of file xml.h.

TSIn& TXmlLx::RSIn
private

Definition at line 102 of file xml.h.

PSIn TXmlLx::SIn
private

Definition at line 101 of file xml.h.

TXmlSpacing TXmlLx::Spacing
private

Definition at line 106 of file xml.h.

TXmlLxSym TXmlLx::Sym

Definition at line 139 of file xml.h.

TStr TXmlLx::TagNm

Definition at line 141 of file xml.h.

TChA TXmlLx::TxtChA

Definition at line 140 of file xml.h.


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