00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00028 #ifndef _RTXCPPXMLSTRING_H_
00029 #define _RTXCPPXMLSTRING_H_
00030
00031 #include "rtxsrc/OSRTBaseType.h"
00032 #include "rtxsrc/OSRTMemBuf.h"
00033 #include "rtxsrc/rtxPrint.h"
00034 #include "rtxsrc/rtxUTF8.h"
00035 #include "rtxsrc/rtxXmlStr.h"
00036
00037 #define DEFAULT_CAPACITY 40
00038
00039 class OSRTMessageBufferIF;
00040 struct OSXMLNamespace;
00041
00046 class EXTRTCLASS OSXMLStringClass : public OSRTBaseType {
00047 protected:
00048 OSUTF8CHAR* value;
00049 OSBOOL cdata;
00050 size_t mCapacityIncrement;
00051 size_t mCurrentBufferSize;
00052 size_t mCurrentStringSize;
00053
00054 size_t getRequiredCapacity (const char* pString) const;
00055 size_t getRequiredCapacity (const OSUTF8CHAR* pString) const;
00056 size_t getRequiredCapacity (size_t numBytesRequired) const;
00057 size_t getLenInBytes (const OSUTF8CHAR* xstr) const;
00058
00059 void newString (const OSUTF8CHAR* pString, size_t nbytes = 0);
00060
00061 inline void newString (const char* pString, size_t nbytes = 0) {
00062 newString ((const OSUTF8CHAR*) pString, nbytes);
00063 }
00064
00065 void xstrncat (OSUTF8CHAR* dststr, const OSUTF8CHAR* srcstr, size_t nbytes);
00066
00067 inline void xstrcat (OSUTF8CHAR* dststr, const OSUTF8CHAR* srcstr) {
00068 xstrncat (dststr, srcstr, getLenInBytes(srcstr));
00069 }
00070
00071 public:
00075 OSXMLStringClass();
00076
00084 OSXMLStringClass (const OSUTF8CHAR* strval,
00085 OSBOOL cdata_ = FALSE);
00086
00096 OSXMLStringClass (const OSUTF8CHAR* strval, size_t nbytes,
00097 OSBOOL cdata_ = FALSE);
00098
00106 OSXMLStringClass (const char* strval,
00107 OSBOOL cdata_ = FALSE);
00108
00114 OSXMLStringClass (const OSXMLSTRING& str);
00115
00121 OSXMLStringClass (const OSXMLStringClass& str);
00122
00127 virtual ~OSXMLStringClass();
00128
00138 void appendValue (const OSUTF8CHAR* utf8str, size_t nbytes = 0);
00139
00144 OSRTBaseType* clone () const { return new OSXMLStringClass (*this); }
00145
00155 void copyValue (const OSUTF8CHAR* utf8str, size_t nbytes = 0);
00156
00166 inline void copyValue (const char* cstring, size_t nbytes = 0) {
00167 copyValue ((const OSUTF8CHAR*) cstring, nbytes);
00168 }
00169
00173 inline const char* c_str () const {
00174 return (const char*)value;
00175 }
00176
00187 virtual int decodeXML (OSCTXT* pctxt);
00188
00202 virtual int encodeXML (OSRTMessageBufferIF& msgbuf,
00203 const OSUTF8CHAR* elemName, OSXMLNamespace* pNS);
00204
00208 inline const OSUTF8CHAR* getValue () const {
00209 return value;
00210 }
00211
00219 inline OSBOOL isCDATA () const { return cdata; }
00220
00228 inline void setCDATA (OSBOOL bvalue) { cdata = bvalue; }
00229
00235 inline void print (const char* name) { rtxPrintUTF8CharStr (name, value); }
00236
00245 void setValue (const OSUTF8CHAR* utf8str, size_t nbytes = 0);
00246
00255 inline void setValue (const char* cstring, size_t nbytes = 0) {
00256 setValue ((const OSUTF8CHAR*) cstring, nbytes);
00257 }
00258
00266 inline void setValue (OSRTMemBuf& membuf) {
00267 setValue (membuf.getData(), membuf.getDataLen());
00268 }
00269
00273 OSXMLStringClass& operator= (const OSXMLStringClass& original);
00274
00278 OSXMLStringClass& operator= (const char* original);
00279
00283 OSXMLStringClass& operator= (const OSUTF8CHAR* original);
00287 inline operator const char* () const { return c_str(); }
00288
00292 inline operator const OSUTF8CHAR* () const { return getValue(); }
00293
00297 inline int length () {
00298 return (value == 0) ? 0 : (int)rtxUTF8Len(value);
00299 }
00300
00304 inline int size () {
00305 return (value == 0) ? 0 : (int)rtxUTF8LenBytes(value);
00306 }
00307
00308 } ;
00309
00310 #endif