Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cXml.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cXml_H
7 #define _INC_cXml_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
16 
17 namespace GrayLib
18 {
22 
24  {
28  CXML_ENCODING_UTF8, // "UTF-8"
29  CXML_ENCODING_UTF16, // "UTF-16"
31  };
32 
33  struct GRAYLIB_LINK cXml // static
34  {
37 
39  {
43 #define cXmlNodeTypeDEF(a,b,c) XMLNODE_##a,
44 #include "cXmlNodeTypes.tbl"
45 #undef cXmlNodeTypeDEF
46  XMLNODE_QTY
47  };
48 
49  static const char k_xmlHeader[6];
50  static const char k_xmlEnd[3];
51  static const char k_commentHeader[5];
52  static const char k_commentEnd[4];
53  static const char k_cdataHeader[10];
54  static const char k_cdataEnd[4];
55  static const char k_dtdHeader[3];
56 
57  static StrLen_t GRAYCALL ParseMicrosoftBOM(const BYTE* pszData);
58  static bool GRAYCALL IsXML(const IniChar_t* pszStr, StrLen_t iLenMax = StrT::k_LEN_MAX);
59  static cXmlString GRAYCALL GetAttributeStr(const IniChar_t* pszName, const cXmlString& sValue);
60 
61  static inline void AddPathElement(cXmlString& sPath, const cXmlString& sElement)
62  {
64  if (!sPath.IsEmpty())
65  {
66  sPath += ".";
67  }
68  sPath += sElement;
69  }
70  static inline void RemovePathElement(cXmlString& sPath, const cXmlString& sElement)
71  {
73  ASSERT(sElement.CompareNoCase(sPath.get_CPtr() + (sPath.GetLength() - sElement.GetLength())) == 0);
74  if (sElement.GetLength() >= sPath.GetLength())
75  {
76  sPath = "";
77  }
78  else
79  {
80  sPath = sPath.substr(0, sPath.GetLength() - (sElement.GetLength() + 1));
81  }
82  }
83  };
84 
86  {
90 
91  public:
92  enum E_TYPE
93  {
96  E_AMP = 0,
97  E_LT,
98  E_GT,
101  E_QTY = 5,
102  // MAX_ENTITY_LENGTH = 6
103  };
104 
105  static const cXmlEntity k_Entity[E_QTY];
106 
107  const char* m_pszName;
109  wchar_t m_chValue;
110 
111  public:
112  static const cXmlEntity* GRAYCALL FindEntityName(const char* pszName);
113  static const cXmlEntity* GRAYCALL FindEntityChar(wchar_t ch);
114 
115  static cXmlString GRAYCALL EncodeString(const cXmlString& sInp, cXmlString sPrefix = "");
116  static const char* GRAYCALL DecodeEntity(const char* pszData, OUT char* pszOutputValue, OUT StrLen_t* piOutputLength, CXML_ENCODING_TYPE eEncoding = CXML_ENCODING_UNKNOWN);
117  };
118 
119  class cXmlEntity2 // : cXmlEntity
120  {
124  public:
127 
128  public:
130  : m_sName(sName)
131  {
132  }
133  bool operator == (const cXmlEntity2& e) const
134  {
135  return(m_sName == e.m_sName && m_sValue == e.m_sValue);
136  }
137  };
138 
139  class cXmlEntitySet : public cArrayStruct<cXmlEntity2>
140  {
143  };
144 };
145 
146 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cXml.h:120
cXmlEntity2(cXmlString sName="")
Definition: cXml.h:129
cXmlString m_sValue
Definition: cXml.h:126
bool operator==(const cXmlEntity2 &e) const
Definition: cXml.h:133
cXmlString m_sName
Definition: cXml.h:125
Definition: cXml.h:140
StrLen_t GetLength() const noexcept
Definition: cString.h:183
bool IsEmpty() const noexcept
Definition: cString.h:176
COMPARE_t CompareNoCase(const _TYPE_CH *pszStr) const
Definition: cString.h:269
Definition: cArray.h:932
Definition: cIniMap.h:18
Definition: cIniMap.h:56
const _TYPE_CH * get_CPtr() const noexcept
Definition: cString.h:419
THIS_t substr(StrLen_t nFirst, StrLen_t nCount=StrT::k_LEN_MAX) const
Definition: cString.h:614
Definition: cMesh.h:22
cIniKeyValue cXmlAttribute
Definition: cXml.h:20
cIniMap cXmlAttributeSet
Definition: cXml.h:21
cStringI cXmlString
Definition: cXml.h:19
CXML_ENCODING_TYPE
Definition: cXml.h:24
@ CXML_ENCODING_UTF8
Definition: cXml.h:28
@ CXML_ENCODING_UTF16
Definition: cXml.h:29
@ CXML_ENCODING_UNKNOWN
Definition: cXml.h:27
@ CXML_ENCODING_LEGACY
Definition: cXml.h:30
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
char IniChar_t
char format even on UNICODE system! Screw M$, INI files should ALWAYS have UTF8 contents
Definition: cIniBase.h:17
Definition: cXml.h:86
wchar_t m_chValue
The result UNICODE char this entity will produce.
Definition: cXml.h:109
E_TYPE
Definition: cXml.h:93
@ E_QUOT
'"'
Definition: cXml.h:99
@ E_LT
'<' = "<"
Definition: cXml.h:97
@ E_APOS
'\''
Definition: cXml.h:100
@ E_GT
'>'
Definition: cXml.h:98
StrLen_t m_nLenName
length of m_pszName including ;
Definition: cXml.h:108
const char * m_pszName
raw string for the entity. e.g. "&"
Definition: cXml.h:107
Definition: cXml.h:34
XMLNODE_TYPE
Definition: cXml.h:39
static void AddPathElement(cXmlString &sPath, const cXmlString &sElement)
Definition: cXml.h:61
static void RemovePathElement(cXmlString &sPath, const cXmlString &sElement)
Definition: cXml.h:70
static const StrLen_t k_LEN_MAX
arbitrary max size for Format() etc. NOTE: _MSC_VER says stack frame should be at least 16384
Definition: StrT.h:75