Beispiel #1
0
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();
			}
		}
	}
}
Beispiel #2
0
//! 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;
                }
            }
        }
    }
}
Beispiel #3
0
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;
}
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;
      }
   }
}
Beispiel #5
0
    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();
                }
            }
        }
    }
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);
}
Beispiel #7
0
		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);
		}
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;
}
Beispiel #9
0
//! Converts escape sequences to the corresponding characters
void char_constants< wchar_t >::translate_escape_sequences(std::basic_string< char_type >& str)
{
    std::basic_string< char_type >::iterator it = str.begin();
    while (it != str.end())
    {
        it = std::find(it, str.end(), L'\\');
        if (std::distance(it, str.end()) >= 2)
        {
            it = str.erase(it);
            switch (*it)
            {
            case L'n':
                *it = L'\n'; break;
            case L'r':
                *it = L'\r'; break;
            case L'a':
                *it = L'\a'; break;
            case L'\\':
                ++it; break;
            case L't':
                *it = L'\t'; break;
            case L'b':
                *it = L'\b'; break;
            case L'x':
                {
                    std::basic_string< char_type >::iterator b = it;
                    if (std::distance(++b, str.end()) >= 2)
                    {
                        char_type c1 = *b++, c2 = *b++;
                        if (iswxdigit(c1) && iswxdigit(c2))
                        {
                            *it++ = char_type((to_number(c1) << 4) | to_number(c2));
                            it = str.erase(it, b);
                        }
                    }
                    break;
                }
            case L'u':
                {
                    std::basic_string< char_type >::iterator b = it;
                    if (std::distance(++b, str.end()) >= 4)
                    {
                        char_type c1 = *b++, c2 = *b++, c3 = *b++, c4 = *b++;
                        if (iswxdigit(c1) && iswxdigit(c2) && iswxdigit(c3) && iswxdigit(c4))
                        {
                            *it++ = char_type(
                                (to_number(c1) << 12) |
                                (to_number(c2) << 8) |
                                (to_number(c3) << 4) |
                                to_number(c4));
                            it = str.erase(it, b);
                        }
                    }
                    break;
                }
            case L'U':
                {
                    std::basic_string< char_type >::iterator b = it;
                    if (std::distance(++b, str.end()) >= 8)
                    {
                        char_type c1 = *b++, c2 = *b++, c3 = *b++, c4 = *b++;
                        char_type c5 = *b++, c6 = *b++, c7 = *b++, c8 = *b++;
                        if (iswxdigit(c1) && iswxdigit(c2) && iswxdigit(c3) && iswxdigit(c4) &&
                            iswxdigit(c5) && iswxdigit(c6) && iswxdigit(c7) && iswxdigit(c8))
                        {
                            *it++ = char_type(
                                (to_number(c1) << 28) |
                                (to_number(c2) << 24) |
                                (to_number(c3) << 20) |
                                (to_number(c4) << 16) |
                                (to_number(c5) << 12) |
                                (to_number(c6) << 8) |
                                (to_number(c7) << 4) |
                                to_number(c8));
                            it = str.erase(it, b);
                        }
                    }
                    break;
                }
            default:
                {
                    if (*it >= L'0' && *it <= L'7')
                    {
                        std::basic_string< char_type >::iterator b = it;
                        int c = (*b++) - L'0';
                        if (*b >= L'0' && *b <= L'7')
                            c = c * 8 + (*b++) - L'0';
                        if (*b >= L'0' && *b <= L'7')
                            c = c * 8 + (*b++) - L'0';

                        *it++ = char_type(c);
                        it = str.erase(it, b);
                    }
                    break;
                }
            }
        }
    }
}
Beispiel #10
0
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;

		if ( redraw )
		{
			m_wnd.clear();
			m_wnd.draw( m_fePresent, t );

			for ( std::vector<sf::Drawable *>::iterator itr=d.begin();
					itr < d.end(); ++itr )
				m_wnd.draw( *(*itr), t );

			m_wnd.draw( cursor, t );
			m_wnd.display();

			redraw = false;
		}
		else
			sf::sleep( sf::milliseconds( 30 ) );

	}
	return true;
}