本文整理汇总了C++中CNativeW::AllocStringBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ CNativeW::AllocStringBuffer方法的具体用法?C++ CNativeW::AllocStringBuffer怎么用?C++ CNativeW::AllocStringBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNativeW
的用法示例。
在下文中一共展示了CNativeW::AllocStringBuffer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Replace
void CNativeW::Replace( const wchar_t* pszFrom, int nFromLen, const wchar_t* pszTo, int nToLen )
{
CNativeW cmemWork;
int nBgnOld = 0;
int nBgn = 0;
while( nBgn <= GetStringLength() - nFromLen ){
if( 0 == wmemcmp( &GetStringPtr()[nBgn], pszFrom, nFromLen ) ){
if( nBgnOld == 0 && nFromLen <= nToLen ){
cmemWork.AllocStringBuffer( GetStringLength() );
}
if( 0 < nBgn - nBgnOld ){
cmemWork.AppendString( &GetStringPtr()[nBgnOld], nBgn - nBgnOld );
}
cmemWork.AppendString( pszTo, nToLen );
nBgn = nBgn + nFromLen;
nBgnOld = nBgn;
}else{
nBgn++;
}
}
if( nBgnOld != 0 ){
if( 0 < GetStringLength() - nBgnOld ){
cmemWork.AppendString( &GetStringPtr()[nBgnOld], GetStringLength() - nBgnOld );
}
SetNativeData( cmemWork );
}else{
if( this->GetStringPtr() == NULL ){
this->SetString(L"");
}
}
}
示例2: ReadLineW
wstring CTextInputStream::ReadLineW()
{
//$$ 非効率だけど今のところは許して。。
CNativeW line;
line.AllocStringBuffer(60);
for (;;) {
int c=getc(GetFp());
if(c==EOF)break; //EOFで終了
if(c=='\r'){ c=getc(GetFp()); if(c!='\n')ungetc(c,GetFp()); break; } //"\r" または "\r\n" で終了
if(c=='\n')break; //"\n" で終了
if( line._GetMemory()->capacity() < line._GetMemory()->GetRawLength() + 10 ){
line._GetMemory()->AllocBuffer( line._GetMemory()->GetRawLength() * 2 );
}
line._GetMemory()->AppendRawData(&c,sizeof(char));
}
//UTF-8 → UNICODE
if(m_bIsUtf8){
CUtf8::UTF8ToUnicode(*(line._GetMemory()), &line);
}
//Shift_JIS → UNICODE
else{
CShiftJis::SJISToUnicode(*(line._GetMemory()), &line);
}
return wstring().assign( line.GetStringPtr(), line.GetStringLength() ); // EOL まで NULL 文字も含める
}
示例3: UnicodeToHex
// 文字コード表示用 UNICODE → Hex 変換 2008/6/21 Uchi
EConvertResult CUtf8::_UnicodeToHex(const wchar_t* cSrc, const int iSLen, TCHAR* pDst, const CommonSetting_Statusbar* psStatusbar, const bool bCESUMode)
{
CNativeW cBuff;
EConvertResult res;
int i;
TCHAR* pd;
unsigned char* ps;
bool bbinary=false;
if (psStatusbar->m_bDispUtf8Codepoint) {
// Unicodeで表示
return CCodeBase::UnicodeToHex(cSrc, iSLen, pDst, psStatusbar);
}
cBuff.AllocStringBuffer(4);
// 1文字データバッファ
if (IsUTF16High(cSrc[0]) && iSLen >= 2 && IsUTF16Low(cSrc[1])) {
cBuff._GetMemory()->SetRawDataHoldBuffer(cSrc, 4);
}
else {
cBuff._GetMemory()->SetRawDataHoldBuffer(cSrc, 2);
if( IsBinaryOnSurrogate(cSrc[0]) ){
bbinary = true;
}
}
// UTF-8/CESU-8 変換
if (bCESUMode != true) {
res = UnicodeToUTF8(cBuff, cBuff._GetMemory());
}
else {
res = UnicodeToCESU8(cBuff, cBuff._GetMemory());
}
if (res != RESULT_COMPLETE) {
return res;
}
// Hex変換
ps = reinterpret_cast<unsigned char*>( cBuff._GetMemory()->GetRawPtr() );
pd = pDst;
if( bbinary == false ){
for (i = cBuff._GetMemory()->GetRawLength(); i >0; i--, ps ++, pd += 2) {
auto_sprintf( pd, _T("%02X"), *ps);
}
}else{
auto_sprintf( pd, _T("?%02X"), *ps );
}
return RESULT_COMPLETE;
}
示例4: ReplaceData
//.........这里部分代码省略.........
CLineData& delLine = pArg->pcmemDeleted->back();
delLine.cmemLine.SetString(&pLine[nWorkPos], nWorkLen);
delLine.nSeq = CModifyVisitor().GetLineModifiedSeq(pCDocLine);
}
/* 次の行がある */
if( pCDocLineNext ){
/* 次の行のデータを最後に追加 */
// 改行を削除するような置換
int nNewLen = nWorkPos + pCDocLineNext->GetLengthWithEOL() + nInsLen;
if( nWorkLen <= nWorkPos && nLineLen <= nNewLen + 10 ){
// 行を連結して1行にするような操作の高速化
// 削除が元データの有効長以下で行の長さが伸びるか少し減る場合reallocを試みる
static CDocLine* pDocLinePrevAccess = NULL;
static int nAccessCount = 0;
int nBufferReserve = nNewLen;
if( pDocLinePrevAccess == pCDocLine ){
if( 100 < nAccessCount ){
if( 1000 < nNewLen ){
int n = 1000;
while( n < nNewLen ){
n += n / 5; // 20%づつ伸ばす
}
nBufferReserve = n;
}
}else{
nAccessCount++;
}
}else{
pDocLinePrevAccess = pCDocLine;
nAccessCount = 0;
}
CNativeW& ref = pCDocLine->_GetDocLineData();
ref.AllocStringBuffer(nBufferReserve);
ref._SetStringLength(nWorkPos);
ref.AppendString(pInsData, nInsLen);
ref.AppendNativeData(pCDocLineNext->_GetDocLineDataWithEOL());
pCDocLine->SetEol();
}else{
CNativeW tmp;
tmp.AllocStringBuffer(nNewLen);
tmp.AppendString(pLine, nWorkPos);
tmp.AppendString(pInsData, nInsLen);
tmp.AppendNativeData(pCDocLineNext->_GetDocLineDataWithEOL());
pCDocLine->SetDocLineStringMove(&tmp);
}
if( bChangeOneLine ){
pArg->nInsSeq = CModifyVisitor().GetLineModifiedSeq(pCDocLine);
CModifyVisitor().SetLineModified(pCDocLine, nSetSeq);
if( !bInsOneLine ){
pArg->ptNewPos.x = pArg->ptNewPos.x + nInsLen;
bInsOneLine = true;
}
}else{
CModifyVisitor().SetLineModified(pCDocLine, pArg->nDelSeq);
// 削除される行のマーク類を保存
markNext = pCDocLineNext->m_sMark;
bSetMark = true;
}
/* 次の行 行オブジェクトの削除 */
m_pcDocLineMgr->DeleteLine( pCDocLineNext );
pCDocLineNext = NULL;
/* 削除した行の総数 */
++(pArg->nDeletedLineNum);