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


C++ basic_string::erase方法代码示例

本文整理汇总了C++中std::basic_string::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::erase方法的具体用法?C++ basic_string::erase怎么用?C++ basic_string::erase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::basic_string的用法示例。


在下文中一共展示了basic_string::erase方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TrimRight

void IO::TrimRight(std::basic_string<charType> & str, const char* chars2remove)
{
	if (!str.empty()) {  	//trim the characters in chars2remove from the right
		std::string::size_type pos = 0;
		if (chars2remove != NULL) {
			pos = str.find_last_not_of(chars2remove);

			if (pos != std::string::npos)
				str.erase(pos+1);
			else
				str.erase( str.begin() , str.end() ); // make empty
		}
		else {       		//trim space
			pos = std::string::npos;
			for (int i = str.size()-1; i >= 0; --i) {
				if (!isspace(str[i])) {
					pos = i;
					break;
				}
			}
			if (pos != std::string::npos) {
				if (pos+1 != str.size())
					str.resize(pos+1);
			}
			else {
				str.clear();
			}
		}
	}
}
开发者ID:AIBluefisher,项目名称:GraphCluster,代码行数:30,代码来源:io_utils.cpp

示例2: while

//! Converts escape sequences to the corresponding characters
void char_constants< char >::translate_escape_sequences(std::basic_string< char_type >& str)
{
    using namespace std; // to make sure we can use C functions unqualified

    std::basic_string< char_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':
                {
                    std::basic_string< char_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')
                    {
                        std::basic_string< char_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;
                }
            }
        }
    }
}
开发者ID:evemu,项目名称:boost,代码行数:60,代码来源:parser_utils.cpp

示例3: regex_split

std::size_t regex_split(OutputIterator out,
                   std::basic_string<charT, Traits1, Alloc1>& s, 
                   const basic_regex<charT, Traits2>& e,
                   match_flag_type flags,
                   std::size_t max_split)
{
   typedef typename std::basic_string<charT, Traits1, Alloc1>::const_iterator  ci_t;
   //typedef typename match_results<ci_t>::allocator_type                        match_allocator;
   ci_t last = s.begin();
   std::size_t init_size = max_split;
   re_detail::split_pred<OutputIterator, charT, Traits1, Alloc1> pred(&last, &out, &max_split);
   ci_t i, j;
   i = s.begin();
   j = s.end();
   regex_grep(pred, i, j, e, flags);
   //
   // if there is still input left, do a final push as long as max_split
   // is not exhausted, and we're not splitting sub-expressions rather 
   // than whitespace:
   if(max_split && (last != s.end()) && (e.mark_count() == 0))
   {
      *out = std::basic_string<charT, Traits1, Alloc1>((ci_t)last, (ci_t)s.end());
      ++out;
      last = s.end();
      --max_split;
   }
   //
   // delete from the string everything that has been processed so far:
   s.erase(0, last - s.begin());
   //
   // return the number of new records pushed:
   return init_size - max_split;
}
开发者ID:13W,项目名称:icq-desktop,代码行数:33,代码来源:regex_split.hpp

示例4: re_trunc_primary

void BOOST_REGEX_CALL re_trunc_primary(std::basic_string<charT>& s)
{
   for(unsigned int i = 0; i < s.size(); ++i)
   {
      if(s[i] <= 1)
      {
         s.erase(i);
         break;
      }
   }
}
开发者ID:DCMF,项目名称:Dawn-of-Civilization,代码行数:11,代码来源:regex_cstring.hpp

示例5: TrimLeft

    void IO::TrimLeft(std::basic_string<charType> & str, const char* chars2remove)
    {
        if (!str.empty())   //trim the characters in chars2remove from the left
        {
            std::string::size_type pos = 0;
            if (chars2remove != NULL)
            {
                pos = str.find_first_not_of(chars2remove);

                if (pos != std::string::npos)
                    str.erase(0,pos);
                else
                    str.erase( str.begin() , str.end() ); // make empty
            }
            else        //trim space
            {
                pos = std::string::npos;        //pos = -1
                for (size_t i = 0; i < str.size(); ++i)
                {
                    if (!isspace(str[i]))
                    {
                        pos = i;
                        break;
                    }
                }
                if (pos != std::string::npos)
                {
                    if (pos > 0)
                    {
                        size_t length = str.size() - pos;
                        for (size_t i = 0; i < length; ++i) str[i] = str[i+pos];
                        str.resize(length);
                    }
                }
                else
                {
                    str.clear();
                }
            }
        }
    }
开发者ID:ZhouCS,项目名称:libvot,代码行数:41,代码来源:io_utils.cpp

示例6: StringTrimLeftT

void StringTrimLeftT(std::basic_string<CharType> &output)
{
	size_t check = 0;
	size_t length = output.length();
	const CharType *src = output.data();

	for (; check < length; check++)
		if (NOT_SPACE(src[check]))
			break;

	output.erase(0, check);
}
开发者ID:arlen7772gg,项目名称:NIM_Duilib_Framework,代码行数:12,代码来源:string_util.cpp

示例7: move

		std::basic_string < Elem, Traits > cell_decode(std::basic_string < Elem, Traits > Str, Elem Sep_, Elem Esc){
			if(Str.size()>1 && Str.front()==Esc && Str.back()==Esc){
				Str.erase(Str.begin());
				Str.pop_back();

				bool EscFlag=false;
				for(auto itr = Str.begin(); itr != Str.end(); ++itr){
					if(*itr == Esc){
						if(EscFlag){
							itr = Str.erase(itr);
							--itr;
							EscFlag = false;
						} else{
							EscFlag = true;
						}
					} else{
						EscFlag = false;
					}
				}
			}

			return std::move(Str);
		}
开发者ID:HomuraVehicle,项目名称:hmLib,代码行数:23,代码来源:csv_iterator.hpp

示例8: ReplaceHtmlEntities

INT ReplaceHtmlEntities(std::basic_string<TCHAR>& htmlText)
{
	INT replaces = 0;
	size_t startPos = htmlText.find(L"&", 0);
	while (startPos != std::wstring::npos)
	{
		size_t nextEndPos = htmlText.find(L";", startPos + 1);
		if (nextEndPos == std::wstring::npos)
		{
			//=== Last &... wasn't an entity & we ve found EOF
			break;
		}
		BOOL bEntityIsValid = TRUE;
		size_t nextStartPos = htmlText.find(L"&", startPos + 1);
		if (nextStartPos != std::wstring::npos)
		{
			if (nextStartPos < nextEndPos)
			{
				//=== We ve found &..&..; pattern which is illegal
				bEntityIsValid = FALSE;
			}
		}
		if (bEntityIsValid)
			bEntityIsValid = ((nextEndPos - startPos) <= 8);
		if (bEntityIsValid)
		{
			wchar_t repVal = 0;
			LPCTSTR entityStart = &htmlText[startPos+1];
			if (*entityStart/*htmlText[startPos+1]*/ == '#')
			{
				//=== It is a int entity
				TCHAR intbf[10];
				INT copyChars = (INT) min(nextEndPos - startPos - 2, 9);
				_tcsncpy(intbf, &htmlText[startPos+2], copyChars);
				intbf[copyChars] = 0;
				INT val = _wtoi(intbf);
				if (val > 0 && val < 0xFFFE)
					repVal = wchar_t(val);
			}
			else
			{
				//=== It is a string entity
				//=== Check the ISO88591 entities
				for (int i = 0; i < sizeof(ISO88591_Entities)/sizeof(LPCTSTR); i++)
				{
					if (_tcsncmp(ISO88591_Entities[i], entityStart, _tcslen(ISO88591_Entities[i])) == 0)
					{
						repVal = (wchar_t) (i + 160);
						break;
					}
				}

				//=== Check the "other" mapped entities
				if (repVal == 0)
				{
					for (int i = 0; i < sizeof(strentity2wchar_t)/sizeof(HtmlStringEntityMap); i++)
					{
						if (_tcsncmp(strentity2wchar_t[i].html, entityStart, _tcslen(strentity2wchar_t[i].html)) == 0)
						{
							repVal = strentity2wchar_t[i].res;
							break;
						}
					}
				}
			}
			if (repVal != 0)
			{
				htmlText.erase(startPos + 1, nextEndPos - startPos);
				htmlText[startPos] = repVal;
				replaces++;
			}
			nextStartPos = htmlText.find(L"&", startPos + 1);
		}
		startPos = nextStartPos;

	}
	//for (int i = 0; i < sizeof(html2text)/sizeof(HtmlEntityMap); i++)
	//	replaces += replace(htmlText, html2text[i].html, html2text[i].text);
	return replaces;
}
开发者ID:KurzedMetal,项目名称:Jaangle,代码行数:80,代码来源:WebPageUtilities.cpp

示例9: edit_loop

bool FeOverlay::edit_loop( std::vector<sf::Drawable *> d,
			std::basic_string<sf::Uint32> &str, FeTextPrimative *tp )
{
	const sf::Transform &t = m_fePresent.get_transform();

	const sf::Font *font = tp->getFont();
	sf::Text cursor( "_", *font, tp->getCharacterSize() );
	cursor.setColor( tp->getColor() );
	cursor.setStyle( sf::Text::Bold );
	cursor.setScale( tp->getTextScale() );

	int cursor_pos=str.size();
	cursor.setPosition( tp->setString( str, cursor_pos ) );

	bool redraw=true;
	FeKeyRepeat key_repeat_enabler( m_wnd );

	while ( m_wnd.isOpen() )
	{
		sf::Event ev;
		while (m_wnd.pollEvent(ev))
		{
			switch ( ev.type )
			{
			case sf::Event::Closed:
				return false;

			case sf::Event::TextEntered:

				switch ( ev.text.unicode )
				{
				case 8: // Backspace
					if ( cursor_pos > 0 )
					{
						str.erase( cursor_pos - 1, 1 );
						cursor_pos--;
					}
					redraw = true;
					break;

				case 9: // horizontal tab
				case 10: // linefeed
				case 13: // Return (ignore here, deal with as keypress event)
					break;

				case 127: // Delete
					if ( cursor_pos < (int)str.size() )
						str.erase( cursor_pos, 1 );

					redraw = true;
					break;

				default: // General text entry
					if ( cursor_pos < (int)str.size() )
						str.insert( cursor_pos, 1, ev.text.unicode );
					else
						str += ev.text.unicode;

					cursor_pos++;
					redraw = true;
				}

				break;

			case sf::Event::KeyPressed:
				switch ( ev.key.code )
				{
				case sf::Keyboard::Left:
					if ( cursor_pos > 0 )
						cursor_pos--;

					redraw = true;
					break;

				case sf::Keyboard::Right:
					if ( cursor_pos < (int)str.size() )
						cursor_pos++;

					redraw = true;
					break;

				case sf::Keyboard::Return:
					return true;

				case sf::Keyboard::Escape:
					return false;

				default:
					break;
				}
			default:
			break;
			}

			if ( redraw )
				cursor.setPosition( tp->setString( str, cursor_pos ) );
		}

		if ( m_fePresent.tick( NULL ) )
			redraw = true;
//.........这里部分代码省略.........
开发者ID:checkist84,项目名称:attract,代码行数:101,代码来源:fe_overlay.cpp


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