本文整理汇总了C++中STRING::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ STRING::clear方法的具体用法?C++ STRING::clear怎么用?C++ STRING::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STRING
的用法示例。
在下文中一共展示了STRING::clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReplaceToSign_Normal
VOID CStringFilter::ReplaceToSign_Normal(const STRING& strIn, STRING& strOut)
{
static STRING strSign = "?";
static BYTE byANSIBegin = 0X20;
static BYTE byANSIEnd = 0X80;
strOut = strIn;
STRING::size_type allsize = m_vIncluce.size();
//包含替换
for(STRING::size_type i = 0; i < m_vIncluce.size(); ++i)
{
STRING::size_type pos = strIn.find(m_vIncluce[i]);
while(STRING::npos != pos)
{
STRING strReplace = "";
STRING::size_type len = m_vIncluce[i].size();
//如果包含替换的是1个字节的ANSI字节,替换前,
//需要确认前一个字节一定不是双字节字符集的前一个字节
BOOL bSkip = FALSE;
if(1 == len && pos > 0)
{
BYTE byChar = strIn[pos-1];
#if 0
char dbgmsg[256];
_snprintf(dbgmsg, 255, "strIn[pos-1]:0x%X(0x%X)\n", strIn[pos-1],byChar);
::OutputDebugString(dbgmsg);
#endif
//不是标准ANSI英文字符
if(!(byChar >= byANSIBegin && byChar <= byANSIEnd || byChar == '\r' || byChar == '\n' || byChar == '\t'))
{
bSkip = TRUE;
}
}
if(!bSkip)
{
for(STRING::size_type k = 0; k < len; ++k, strReplace += strSign);
strOut.replace(pos, len, strReplace);
}
pos = strIn.find(m_vIncluce[i], pos+len);
}
}
//完全匹配替换
if(IsFullCmp(strIn))
{
STRING::size_type len = strIn.size();
strOut.clear();
for(STRING::size_type i = 0; i < len; ++i, strOut += strSign);
}
}
示例2: trim
static void trim(STRING& str)
{
static const WCHAR Spaces[] = L" \t\r\n";
size_t i = str.find_first_not_of(Spaces);
size_t j = str.find_last_not_of(Spaces);
if (i == STRING::npos || j == STRING::npos)
{
str.clear();
}
else
{
str = str.substr(i, j - i + 1);
}
}
示例3: fgets
static void fgets(STRING & s, FILE * f)
{
s.resize(0);
char c;
while (fgetc(c, f))
{
if (c == '\n' || c == '\r')
{
if (c == '\r' && (!fgetc(c, f) || c != '\n'))
RuntimeError("fgets: malformed text file, CR without LF");
break;
}
s.push_back(c);
// strip Unicode BOM
// We strip it from any string, not just at the start.
// This allows to UNIX-'cat' multiple UTF-8 files with BOMs.
// Since the BOM is otherwise invalid within a file, this is well-defined and upwards compatible.
if (s.size() == 3 && BeginsWithUnicodeBOM(s.c_str()))
s.clear();
}
}
示例4: ReplaceToSign_New
VOID CStringFilter::ReplaceToSign_New(const STRING& strIn, STRING& strOut)
{
static STRING strSign = "~$%^&(){}`-_+=?,.<>";
strOut = strIn;
STRING::size_type allsize = m_vIncluce.size();
//包含替换
for(STRING::size_type i = 0; i < m_vIncluce.size(); ++i)
{
STRING::size_type pos = strIn.find(m_vIncluce[i]);
while(STRING::npos != pos)
{
STRING strReplace = "";
STRING::size_type len = m_vIncluce[i].size();
for(STRING::size_type k = 0; k < len; ++k)
{
STRING::size_type ri = rand()%int(strSign.size());
strReplace += strSign.at(ri);
}
strOut.replace(pos, len, strReplace);
pos = strIn.find(m_vIncluce[i], pos+len);
}
}
//完全匹配替换
if(IsFullCmp(strIn))
{
STRING::size_type len = strIn.size();
strOut.clear();
for(STRING::size_type i = 0; i < len; ++i)
{
STRING::size_type ri = rand()%int(strSign.size());
strOut += strSign.at(ri);
}
}
}
示例5: ReplaceToSign
//.........这里部分代码省略.........
//0. push normal replace str
pc.bReplace = TRUE;
pc.pice = strSrc.substr(sC, sE-sC);
vSrcPice.push_back(pc);
//1. push no replace str
pc.bReplace = FALSE;
pc.pice = strSrc.substr(sE, sIDEnd-sE+1);
vSrcPice.push_back(pc);
}
//step to new point.
sE = sIDEnd + 1;
sC = sE;
}
else if(strInfoMsg == "_INFOMSG")
{
//get info message
INT nContentsLen = atoi(strSrc.substr(sE+2+8,3).c_str());
STRING::size_type sIDEnd = sE+2+8+3+nContentsLen;
if(sE+2+8 >= sLen)
{
//skip invalid #{
sE += 2;
goto LengthOver2;
}
//ok, valid info message found.
//0. push normal replace str
pc.bReplace = TRUE;
pc.pice = strSrc.substr(sC, sE-sC);
vSrcPice.push_back(pc);
//1. push no replace str
pc.bReplace = FALSE;
pc.pice = strSrc.substr(sE, sIDEnd-sE+1);
vSrcPice.push_back(pc);
//step to new point.
sE = sIDEnd + 1;
sC = sE;
}
else
{
//all other things
sE += 2;
}
}
else
{
//single #
sE += 1;
}
LengthOver2:
if(sE >= sLen)
{
if(sC != sE)
{
//push last replace str
pc.bReplace = TRUE;
pc.pice = strSrc.substr(sC);
vSrcPice.push_back(pc);
}
break;
}
//save new begin point
sB = sE;
//find next KeyStart
sE = strSrc.find(KeyStart, sB);
}while(TRUE);
//替换字串中的非法字符
for(INT i = 0; i < (INT)vSrcPice.size(); ++i)
{
#if 0
_snprintf(dbgmsg, 255, "vSrcPice[%d]:%s\n", i, vSrcPice[i].pice.c_str());
::OutputDebugString(dbgmsg);
#endif
if(TRUE == vSrcPice[i].bReplace)
{
STRING strOld = vSrcPice[i].pice;
ReplaceToSign_Normal(strOld, vSrcPice[i].pice);
}
}
//生成结果字串
strOut.clear();
for(INT i = 0; i < (INT)vSrcPice.size(); ++i)
{
strOut += vSrcPice[i].pice;
}
#if 0
::OutputDebugString("ReplaceToSign End=========================\n");
#endif
}