本文整理汇总了C++中KviCString::trim方法的典型用法代码示例。如果您正苦于以下问题:C++ KviCString::trim方法的具体用法?C++ KviCString::trim怎么用?C++ KviCString::trim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KviCString
的用法示例。
在下文中一共展示了KviCString::trim方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bufferFromBlock
void bufferFromBlock(KviCString & szBuffer)
{
szBuffer.trim();
if((*(szBuffer.ptr()) == '{') && szBuffer.lastCharIs('}'))
{
// leading and trailing { must be stripped
szBuffer.cutLeft(1);
szBuffer.cutRight(1);
}
unindent(szBuffer);
szBuffer.trim();
}
示例2: hasLeadingChars
bool hasLeadingChars(KviCString ** pszArray, char c)
{
if(!(*pszArray))
return false; // can't have more leading chars
bool bGotIt = false;
while(*pszArray)
{
if(*((*pszArray)->ptr()) == c)
{
// found at least one such leading char
bGotIt = true;
} else {
// we pretend this line to be empty
KviCString szTmp = *(*pszArray);
szTmp.trim();
if(szTmp.hasData())
return false;
*(*pszArray) = ""; // set it to empty also in the main buffer
}
pszArray++;
}
return bGotIt;
}
示例3: processHeader
bool KviHttpRequest::processHeader(KviCString &szHeader)
{
int idx = szHeader.findFirstIdx("\r\n");
KviCString szResponse;
if(idx != -1)
{
szResponse = szHeader.left(idx);
szHeader.cutLeft(idx + 2);
} else {
szResponse = szHeader;
szHeader = "";
}
szResponse.trim();
bool bValid = false;
unsigned int uStatus = 0;
// check the response value
if(kvi_strEqualCSN(szResponse.ptr(),"HTTP",4))
{
KviCString szR = szResponse;
szR.cutToFirst(' ');
szR.trim();
int idx = szR.findFirstIdx(' ');
KviCString szNumber;
if(idx != -1)szNumber = szR.left(idx);
else szNumber = szR;
bool bOk;
uStatus = szNumber.toUInt(&bOk);
if(bOk)bValid = true;
}
QString szUniResponse = QString::fromUtf8(szResponse.ptr());
if(!bValid)
{
// the response is invalid ?
resetInternalStatus();
m_szLastError = __tr2qs("Invalid HTTP response: %1").arg(szUniResponse);
emit terminated(false);
return false;
}
emit status(__tr2qs("Received HTTP response: %1").arg(szUniResponse));
KviPointerList<KviCString> hlist;
hlist.setAutoDelete(true);
idx = szHeader.findFirstIdx("\r\n");
while(idx != -1)
{
if(idx > 0)
{
hlist.append(new KviCString(szHeader.ptr(),idx));
szHeader.cutLeft(idx + 2);
}
idx = szHeader.findFirstIdx("\r\n");
}
if(szHeader.hasData())hlist.append(new KviCString(szHeader));
KviPointerHashTable<const char *,KviCString> hdr(11,false,true);
hdr.setAutoDelete(true);
for(KviCString * s = hlist.first();s;s = hlist.next())
{
idx = s->findFirstIdx(":");
if(idx != -1)
{
KviCString szName = s->left(idx);
s->cutLeft(idx + 1);
s->trim();
hdr.replace(szName.ptr(),new KviCString(*s));
//qDebug("FOUND HEADER (%s)=(%s)",szName.ptr(),s->ptr());
}
}
KviCString * size = hdr.find("Content-length");
if(size)
{
bool bOk;
m_uTotalSize = size->toUInt(&bOk);
if(!bOk)m_uTotalSize = 0;
}
KviCString * contentEncoding = hdr.find("Content-encoding");
if(contentEncoding)
{
m_bGzip = contentEncoding->equalsCI("gzip");
}
KviCString * transferEncoding = hdr.find("Transfer-Encoding");
if(transferEncoding)
{
if(kvi_strEqualCI(transferEncoding->ptr(),"chunked"))
{
// be prepared to handle the chunked transfer encoding as required by HTTP/1.1
m_bChunkedTransferEncoding = true;
m_uRemainingChunkSize = 0;
//.........这里部分代码省略.........
示例4: load
//.........这里部分代码省略.........
KviMemory::free(pcBuffer);
f.close();
return false;
}
// Check for broken *.mo files
if(uSize < (24 + (sizeof(GnuMoStringDescriptor) * iStringsNum)))
{
qDebug("KviLocale: Broken translation file %s (too small for all descriptors)",szCatalogueFile.toUtf8().data());
KviMemory::free(pcBuffer);
f.close();
return false;
}
GnuMoStringDescriptor * pOrigDescriptor = (GnuMoStringDescriptor *)(pcBuffer + KVI_SWAP_IF_NEEDED(bMustSwap,hdr.orig_tab_offset));
GnuMoStringDescriptor * pTransDescriptor = (GnuMoStringDescriptor *)(pcBuffer + KVI_SWAP_IF_NEEDED(bMustSwap,hdr.trans_tab_offset));
// Check again for broken *.mo files
int iExpectedFileSize = KVI_SWAP_IF_NEEDED(bMustSwap,pTransDescriptor[iStringsNum - 1].offset) +
KVI_SWAP_IF_NEEDED(bMustSwap,pTransDescriptor[iStringsNum - 1].length);
if(uSize < (unsigned int)iExpectedFileSize)
{
qDebug("KviLocale: Broken translation file %s (too small for all the message strings)",szCatalogueFile.toUtf8().data());
KviMemory::free(pcBuffer);
f.close();
return false;
}
// Ok...we can run now
int iDictSize = kvi_getFirstBiggerPrime(iStringsNum);
if(m_pMessages)
delete m_pMessages;
m_pMessages = new KviPointerHashTable<const char *,KviTranslationEntry>(iDictSize,true,false); // dictSize, case sensitive, don't copy keys
m_pMessages->setAutoDelete(true);
KviCString szHeader;
for(int i = 0; i < iStringsNum; i++)
{
// FIXME: "Check for NULL inside strings here ?"
//qDebug("original seems to be at %u and %u byttes long",KVI_SWAP_IF_NEEDED(bMustSwap,pOrigDescriptor[i].offset),
// KVI_SWAP_IF_NEEDED(bMustSwap,pOrigDescriptor[i].length));
//qDebug("translated seems to be at %u and %u byttes long",KVI_SWAP_IF_NEEDED(bMustSwap,pTransDescriptor[i].offset),
// KVI_SWAP_IF_NEEDED(bMustSwap,pTransDescriptor[i].length));
KviTranslationEntry * e = new KviTranslationEntry(
(char *)(pcBuffer + KVI_SWAP_IF_NEEDED(bMustSwap,pOrigDescriptor[i].offset)),
KVI_SWAP_IF_NEEDED(bMustSwap,pOrigDescriptor[i].length),
(char *)(pcBuffer + KVI_SWAP_IF_NEEDED(bMustSwap,pTransDescriptor[i].offset)),
KVI_SWAP_IF_NEEDED(bMustSwap,pTransDescriptor[i].length));
// In some (or all?) *.mo files the first string
// is zero bytes long and the translated one contains
// information about the translation
if(e->m_szKey.len() == 0)
{
szHeader = e->m_szEncodedTranslation;
delete e;
continue;
}
m_pMessages->insert(e->m_szKey.ptr(),e);
}
KviMemory::free(pcBuffer);
f.close();
m_pTextCodec = 0;
// find out the text encoding, if possible
if(szHeader.hasData())
{
// find "charset=*\n"
int iIdx = szHeader.findFirstIdx("charset=");
if(iIdx != -1)
{
szHeader.cutLeft(iIdx + 8);
szHeader.cutFromFirst('\n');
szHeader.trim();
m_pTextCodec = KviLocale::instance()->codecForName(szHeader.ptr());
if(!m_pTextCodec)
{
qDebug("Can't find the codec for charset=%s",szHeader.ptr());
qDebug("Falling back to codecForLocale()");
m_pTextCodec = QTextCodec::codecForLocale();
}
}
}
if(!m_pTextCodec)
{
qDebug("The message catalogue does not have a \"charset\" header");
qDebug("Assuming utf8"); // FIXME: or codecForLocale() ?
m_pTextCodec = QTextCodec::codecForName("UTF-8");
}
return true;
}