本文整理汇总了C++中string_type::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ string_type::erase方法的具体用法?C++ string_type::erase怎么用?C++ string_type::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string_type
的用法示例。
在下文中一共展示了string_type::erase方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
//! Converts escape sequences to the corresponding characters
void char_constants< char >::translate_escape_sequences(string_type& str)
{
using namespace std; // to make sure we can use C functions unqualified
string_type::iterator it = str.begin();
while (it != str.end())
{
it = std::find(it, str.end(), '\\');
if (std::distance(it, str.end()) >= 2)
{
it = str.erase(it);
switch (*it)
{
case 'n':
*it = '\n'; break;
case 'r':
*it = '\r'; break;
case 'a':
*it = '\a'; break;
case '\\':
++it; break;
case 't':
*it = '\t'; break;
case 'b':
*it = '\b'; break;
case 'x':
{
string_type::iterator b = it;
if (std::distance(++b, str.end()) >= 2)
{
char_type c1 = *b++, c2 = *b++;
if (isxdigit(c1) && isxdigit(c2))
{
*it++ = char_type((to_number(c1) << 4) | to_number(c2));
it = str.erase(it, b);
}
}
break;
}
default:
{
if (*it >= '0' && *it <= '7')
{
string_type::iterator b = it;
int c = (*b++) - '0';
if (*b >= '0' && *b <= '7')
c = c * 8 + (*b++) - '0';
if (*b >= '0' && *b <= '7')
c = c * 8 + (*b++) - '0';
*it++ = char_type(c);
it = str.erase(it, b);
}
break;
}
}
}
}
}
示例2: BYTE_ConvertFromHexStringToArray
int CCommonFnc::BYTE_ConvertFromHexStringToArray(string_type hexaString, BYTE* pArray, DWORD* pbArrayLen) {
int status = STAT_OK;
DWORD pos = 0;
DWORD pos2 = 0;
string_type hexNum;
DWORD num;
BYTE* pTempArray = NULL;
DWORD tempArrayPos = 0;
// EAT SPACES
//hexaString.TrimLeft(); hexaString.TrimRight();
hexaString.erase(hexaString.find_last_not_of(_CONV(" ")) + 1);
size_t startpos = hexaString.find_first_not_of(_CONV(" "));
if (string_type::npos != startpos) {
hexaString = hexaString.substr(startpos);
}
hexaString += _CONV(" ");
hexaString.length();
if (status == STAT_OK) {
pTempArray = new BYTE[hexaString.length()];
memset(pTempArray, 0, hexaString.length());
pos = pos2 = 0;
/*while ((pos = hexaString.Find(' ', pos2)) != -1) {
hexNum = hexaString.Mid(pos2, pos - pos2);
hexNum.TrimLeft(); hexNum.TrimRight();
if (hexNum.GetLength() > 0) {
num = strtol((LPCTSTR) hexNum, NULL, 16);
if (num == 0xFF) pTempArray[tempArrayPos] = 0xFF;
else pTempArray[tempArrayPos] = (BYTE) num & 0xFF;
tempArrayPos++;
}
pos2 = pos + 1;
}*/
while ((pos = hexaString.find(' ', pos2)) != string_type::npos) {
hexNum = hexaString.substr((pos2, pos - pos2));
hexNum.erase(hexNum.find_last_not_of(_CONV(" ")) + 1);
size_t startpos2 = hexNum.find_first_not_of(_CONV(" "));
if (string_type::npos != startpos2) {
hexNum = hexNum.substr(startpos2);
}
if (hexNum.length() > 0) {
num = type_to_int((LPCTSTR)hexNum.c_str(), NULL, 16);
if (num == 0xFF) pTempArray[tempArrayPos] = 0xFF;
else pTempArray[tempArrayPos] = (BYTE)num & 0xFF;
tempArrayPos++;
}
pos2 = pos + 1;
}
if (tempArrayPos > *pbArrayLen) {
status = STAT_NOT_ENOUGHT_MEMORY;
}
else {
memcpy(pArray, pTempArray, tempArrayPos);
}
*pbArrayLen = tempArrayPos;
if (pTempArray) delete[] pTempArray;
}
return status;
}
示例3: expand_escapes
void expand_escapes(string_type& s)
{
for(unsigned int i = 0; i < s.size(); ++i)
{
if(s[i] == BOOST_RE_STR('\\'))
{
switch(s[i+1])
{
case BOOST_RE_STR('a'):
s.erase(s.begin() + i);
s[i] = BOOST_RE_STR('\a');
break;
case BOOST_RE_STR('b'):
s.erase(s.begin() + i);
s[i] = BOOST_RE_STR('\b');
break;
case BOOST_RE_STR('f'):
s.erase(s.begin() + i);
s[i] = BOOST_RE_STR('\f');
break;
case BOOST_RE_STR('n'):
s.erase(s.begin() + i);
s[i] = BOOST_RE_STR('\n');
break;
case BOOST_RE_STR('r'):
s.erase(s.begin() + i);
s[i] = BOOST_RE_STR('\r');
break;
case BOOST_RE_STR('t'):
s.erase(s.begin() + i);
s[i] = BOOST_RE_STR('\t');
break;
case BOOST_RE_STR('v'):
s.erase(s.begin() + i);
s[i] = BOOST_RE_STR('\v');
break;
default:
if( (s[i + 1] >= BOOST_RE_STR('0')) && (s[i + 1] <= BOOST_RE_STR('9')) )
{
int val = 0;
unsigned int pos = i;
++i;
while((i < s.size()) && (s[i] >= BOOST_RE_STR('0')) && (s[i] <= BOOST_RE_STR('9')))
{
val *= 10;
val += s[i] - BOOST_RE_STR('0');
++i;
}
s.erase(s.begin() + pos, s.begin() + i);
if(0 == val)
{
s.insert(s.begin()+pos, ' ');
s[pos] = 0;
}
else
s.insert(s.begin() + pos, (string_type::value_type)val);
i = pos;
}
else
{
s.erase(s.begin() + i);
}
}
}
}
}