示例#1
0
void StrUtils::trimright( wstring& s )
{
	wstring::difference_type dt;
	wstring::reverse_iterator it;

	for( it = s.rbegin(); it != s.rend(); it++ )
		if( !StrUtils::isspace( *it ) )
			break;

	dt = s.rend() - it;

	s.erase( s.begin() + dt, s.end() );
}
示例#2
0
文件: string.cpp 项目: vjcagay/taiga
void ErasePunctuation(wstring& str, bool keep_trailing) {
  auto rlast = str.rbegin();

  if (keep_trailing)
    rlast = std::find_if(str.rbegin(), str.rend(),
        [](wchar_t c) -> bool {
          return !(c == L'!' || // "Hayate no Gotoku!", "K-ON!"...
                   c == L'+' || // "Needless+"
                   c == L'\''); // "Gintama'"
        });

  auto it = std::remove_if(str.begin(), rlast.base(),
      [](int c) -> bool {
        // Control codes, white-space and punctuation characters
        if (c <= 255 && !isalnum(c))
          return true;
        // Unicode stars, hearts, notes, etc. (0x2000-0x2767)
        if (c > 8192 && c < 10087)
          return true;
        // Valid character
        return false;
      });

  if (keep_trailing)
    std::copy(rlast.base(), str.end(), it);

  str.resize(str.size() - (rlast.base() - it));
}
示例#3
0
bool isHuli(const wstring &hid) {
    if(hid.empty())
        return true;
    int stat = 0;
    bool continuestat = true;
    for(std::wstring::const_reverse_iterator it = hid.rbegin(); it != hid.rend(); ++it) {
        switch(stat) {
        case 0:
            if(*it == _T('F') || *it == _T('S') || *it == _T('U') || *it == _T('G'))
            {
                stat = 1;
            } else if(iswdigit(*it)) {
                stat = 4;
            } else {
                continuestat = false;
            }
            break;
        case 1:
            if(*it == _T('@')) {
                stat = 2;
            } else {
                continuestat = false;
            }
            break;
        case 2:
            if(*it == _T('_')) {
                stat = 3;
            } else {
                continuestat = false;
            }
            break;
        case 3:
            if(!iswdigit(*it)) {
                continuestat = false;
            } else {
                stat = 4;
            }
            break;
        case 4:
            if(!iswdigit(*it)) {
                continuestat = false;
            }
            break;
        }
        if(!continuestat) {
            break;
        }
    }
    return continuestat && stat == 4;
}
示例#4
0
wstring trim( wstring text)
{
    text.erase( text.begin(), find_if( text.begin(), text.end(), not1( ptr_fun<wint_t, int>( iswspace ) ) ) );
    text.erase( find_if( text.rbegin(), text.rend(), not1( ptr_fun<wint_t, int>( iswspace ) )).base(), text.end() );
    return text;
}
wstring StringUtilities::RightTrim(wstring str)
{
    str.erase(find_if(str.rbegin(), str.rend(), not1(std::ptr_fun<int, int>(std::isspace))).base(), str.end());
    return str;
}