📄 xmlformatter.hpp
字号:
XMLFormatter ( const char* const outEncoding , const char* const docVersion , XMLFormatTarget* const target , const EscapeFlags escapeFlags = NoEscapes , const UnRepFlags unrepFlags = UnRep_Fail , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager ); XMLFormatter ( const XMLCh* const outEncoding , XMLFormatTarget* const target , const EscapeFlags escapeFlags = NoEscapes , const UnRepFlags unrepFlags = UnRep_Fail , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager ); XMLFormatter ( const char* const outEncoding , XMLFormatTarget* const target , const EscapeFlags escapeFlags = NoEscapes , const UnRepFlags unrepFlags = UnRep_Fail , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager ); ~XMLFormatter(); //@} // ----------------------------------------------------------------------- // Formatting methods // ----------------------------------------------------------------------- /** @name Formatting methods */ //@{ /** * @param toFormat the string to be formatted * @param count length of the string * @param escapeFlags the escape style for formatting toFormat * @param unrepFlags the reaction for any unrepresentable character in toFormat * */ void formatBuf ( const XMLCh* const toFormat , const unsigned int count , const EscapeFlags escapeFlags = DefaultEscape , const UnRepFlags unrepFlags = DefaultUnRep ); /** * @see formatBuf */ XMLFormatter& operator<< ( const XMLCh* const toFormat ); XMLFormatter& operator<< ( const XMLCh toFormat ); void writeBOM(const XMLByte* const toFormat , const unsigned int count); //@} // ----------------------------------------------------------------------- // Getter methods // ----------------------------------------------------------------------- /** @name Getter methods */ //@{ /** * @return return the encoding set for the formatted content */ const XMLCh* getEncodingName() const; /** * @return return the transcoder used internally for transcoding the formatter conent */ inline const XMLTranscoder* getTranscoder() const; //@} // ----------------------------------------------------------------------- // Setter methods // ----------------------------------------------------------------------- /** @name Setter methods */ //@{ /** * @param newFlags set the escape style for the follow-on formatted content */ void setEscapeFlags ( const EscapeFlags newFlags ); /** * @param newFlags set the reaction for unrepresentable character */ void setUnRepFlags ( const UnRepFlags newFlags ); /** * @param newFlags set the escape style for the follow-on formatted content * @see setEscapeFlags */ XMLFormatter& operator<< ( const EscapeFlags newFlags ); /** * @param newFlags set the reaction for unrepresentable character * @see setUnRepFlags */ XMLFormatter& operator<< ( const UnRepFlags newFlags ); //@}private : // ----------------------------------------------------------------------- // Unimplemented constructors and operators // ----------------------------------------------------------------------- XMLFormatter(); XMLFormatter(const XMLFormatter&); XMLFormatter& operator=(const XMLFormatter&); // ----------------------------------------------------------------------- // Private class constants // ----------------------------------------------------------------------- enum Constants { kTmpBufSize = 16 * 1024 }; // ----------------------------------------------------------------------- // Private helper methods // ----------------------------------------------------------------------- const XMLByte* getCharRef(unsigned int & count, XMLByte* &ref, const XMLCh * stdRef); void writeCharRef(const XMLCh &toWrite); void writeCharRef(unsigned long toWrite); bool inEscapeList(const XMLFormatter::EscapeFlags escStyle , const XMLCh toCheck); unsigned int handleUnEscapedChars(const XMLCh * srcPtr, const unsigned int count, const UnRepFlags unrepFlags); void specialFormat ( const XMLCh* const toFormat , const unsigned int count , const EscapeFlags escapeFlags ); // ----------------------------------------------------------------------- // Private, non-virtual methods // // fEscapeFlags // The escape flags we were told to use in formatting. These are // defaults set in the ctor, which can be overridden on a particular // call. // // fOutEncoding // This the name of the output encoding. Saved mainly for meaningful // error messages. // // fTarget // This is the target object for the formatting operation. // // fUnRepFlags // The unrepresentable flags that indicate how to react when a // character cannot be represented in the target encoding. // // fXCoder // This the transcoder that we will use. It is created using the // encoding name we were told to use. // // fTmpBuf // An output buffer that we use to transcode chars into before we // send them off to be output. // // fAposRef // fAmpRef // fGTRef // fLTRef // fQuoteRef // These are character refs for the standard char refs, in the // output encoding. They are faulted in as required, by transcoding // them from fixed Unicode versions. // // fIsXML11 // for performance reason, we do not store the actual version string // and do the string comparison again and again. // // ----------------------------------------------------------------------- EscapeFlags fEscapeFlags; XMLCh* fOutEncoding; XMLFormatTarget* fTarget; UnRepFlags fUnRepFlags; XMLTranscoder* fXCoder; XMLByte fTmpBuf[kTmpBufSize + 4]; XMLByte* fAposRef; unsigned int fAposLen; XMLByte* fAmpRef; unsigned int fAmpLen; XMLByte* fGTRef; unsigned int fGTLen; XMLByte* fLTRef; unsigned int fLTLen; XMLByte* fQuoteRef; unsigned int fQuoteLen; bool fIsXML11; MemoryManager* fMemoryManager;};class XMLPARSER_EXPORT XMLFormatTarget : public XMemory{public: // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- virtual ~XMLFormatTarget() {} // ----------------------------------------------------------------------- // Virtual interface // ----------------------------------------------------------------------- virtual void writeChars ( const XMLByte* const toWrite , const unsigned int count , XMLFormatter* const formatter ) = 0; virtual void flush() {};protected : // ----------------------------------------------------------------------- // Hidden constructors and operators // ----------------------------------------------------------------------- XMLFormatTarget() {};private: // ----------------------------------------------------------------------- // Unimplemented constructors and operators // ----------------------------------------------------------------------- XMLFormatTarget(const XMLFormatTarget&); XMLFormatTarget& operator=(const XMLFormatTarget&);};// ---------------------------------------------------------------------------// XMLFormatter: Getter methods// ---------------------------------------------------------------------------inline const XMLCh* XMLFormatter::getEncodingName() const{ return fOutEncoding;}inline const XMLTranscoder* XMLFormatter::getTranscoder() const{ return fXCoder;}// ---------------------------------------------------------------------------// XMLFormatter: Setter methods// ---------------------------------------------------------------------------inline void XMLFormatter::setEscapeFlags(const EscapeFlags newFlags){ fEscapeFlags = newFlags;}inline void XMLFormatter::setUnRepFlags(const UnRepFlags newFlags){ fUnRepFlags = newFlags;}inline XMLFormatter& XMLFormatter::operator<<(const EscapeFlags newFlags){ fEscapeFlags = newFlags; return *this;}inline XMLFormatter& XMLFormatter::operator<<(const UnRepFlags newFlags){ fUnRepFlags = newFlags; return *this;}XERCES_CPP_NAMESPACE_END#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -