?? xmlstringlate.cpp
字號:
// XMLStringTranslate.cpp: implementation of the XMLStringTranslate class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "XMLStringTranslate.h"
#include <xercesc/util/XMLString.hpp>
#include <xercesc\util\platformutils.hpp>
#include <xercesc\util\transservice.hpp>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
XMLStringTranslate::XMLStringTranslate(const char * const encoding):fFormatter(0),
m_value(0),fEncodingUsed(0),toFill(0)
{
// XMLFormatTarget * myFormTarget = new XMLStringTranslate;
fEncodingUsed=XMLString::transcode(encoding);
fFormatter = new XMLFormatter(fEncodingUsed
,this
,XMLFormatter::NoEscapes
,XMLFormatter::UnRep_CharRef);
toFill=new XMLCh[kTmpBufSize];
clearbuffer();
}
XMLStringTranslate::~XMLStringTranslate()
{
if(fFormatter)
delete fFormatter;
if(fEncodingUsed)
delete [] fEncodingUsed;
if(m_value)
free(m_value);
if(toFill)
free(toFill);
fFormatter=0;
fEncodingUsed=0;
m_value=0;
toFill=0;
}
void XMLStringTranslate::writeChars(const XMLByte* const toWrite
, const unsigned int count
, XMLFormatter* const formatter)
{
// Surprisingly, Solaris was the only platform on which
// required the char* cast to print out the string correctly.
// Without the cast, it was printing the pointer value in hex.
// Quite annoying, considering every other platform printed
// the string with the explicit cast to char* below.
/// cout.write((char *) toWrite, (int) count);
// cout.flush();
if(m_value)
free(m_value);
m_value=0;
m_value=new char[count+1];
memset(m_value,0,count+1);
memcpy(m_value,(char *)toWrite,count+1);
}
void XMLStringTranslate::clearbuffer()
{
if(!toFill)
return;
for(int i=0;i<kTmpBufSize;i++)
toFill[i]=0;
}
string XMLStringTranslate::translate(const XMLCh* const value)
{
*fFormatter<<value;
string strValue=string(m_value);
return strValue;
}
// Function name : XMLStringTranslate::translate
// Description : 將字符串value轉換為XMLCh
// Return type : XMLCh * 轉換過的字符竄,注意內存釋放
// Argument : const char * const value
const XMLCh * const XMLStringTranslate::translate(const char * const value)
{
clearbuffer();
const unsigned int srcCount=XMLString::stringLen(value);
unsigned char fCharSizeBuf[kCharBufSize];
XMLTranscoder * pTranscoder=(XMLTranscoder *)fFormatter->getTranscoder();
unsigned int bytesEaten;
unsigned int size=pTranscoder->transcodeFrom
(
(XMLByte *)value,
srcCount,
toFill,
kTmpBufSize,
bytesEaten,
fCharSizeBuf
);
// toFill[size]=0;
string t1=string(value);
string t2=translate(toFill);
assert(t1==t2);
return toFill;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -