当前位置: 首页>>代码示例>>C++>>正文


C++ STRING::clear方法代码示例

本文整理汇总了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);
	}
}
开发者ID:jjiezheng,项目名称:pap_full,代码行数:53,代码来源:UIString_Filter.cpp

示例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);
    }
}
开发者ID:Moteesh,项目名称:reactos,代码行数:14,代码来源:fontsub.cpp

示例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();
    }
}
开发者ID:BorisJineman,项目名称:CNTK,代码行数:21,代码来源:File.cpp

示例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);
		}
	}
}
开发者ID:jjiezheng,项目名称:pap_full,代码行数:37,代码来源:UIString_Filter.cpp

示例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

}
开发者ID:jjiezheng,项目名称:pap_full,代码行数:101,代码来源:UIString_Filter.cpp


注:本文中的STRING::clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。