本文整理汇总了C++中tstring::find_first_not_of方法的典型用法代码示例。如果您正苦于以下问题:C++ tstring::find_first_not_of方法的具体用法?C++ tstring::find_first_not_of怎么用?C++ tstring::find_first_not_of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tstring
的用法示例。
在下文中一共展示了tstring::find_first_not_of方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Tokenize
void Tokenize( const tstring& str, std::vector< T >& tokens, const tstring& delimiters )
{
// Skip delimiters at beginning.
tstring::size_type lastPos = str.find_first_not_of( delimiters, 0 );
// Find first "non-delimiter".
tstring::size_type pos = str.find_first_of( delimiters, lastPos );
I temp;
while ( tstring::npos != pos || tstring::npos != lastPos )
{
// Found a token, convert it to the proper type for our vector
tstringstream stream (str.substr( lastPos, pos - lastPos ));
stream >> temp; // NOTE: Stream operator stops at spaces!
if ( !stream.fail() )
{
// Add the token to the vector
tokens.push_back( (T)temp );
}
else
{
HELIUM_BREAK();
}
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of( delimiters, pos );
// Find next "non-delimiter"
pos = str.find_first_of( delimiters, lastPos );
}
}
示例2:
CTokenizer::CTokenizer(const tstring& p_Str, const tstring& p_Delimiters)
{
const tstring::size_type len = p_Str.length();
tstring::size_type i = 0;
while(i < len)
{
// eat leading whitespace
i = p_Str.find_first_not_of(p_Delimiters, i);
if(i == tstring::npos)
return; // nothing left but white space
// find the end of the token
tstring::size_type j = p_Str.find_first_of(p_Delimiters, i);
// push token
if(j == tstring::npos)
{
m_Tokens.push_back(p_Str.substr(i));
return;
} else
m_Tokens.push_back(p_Str.substr(i, j - i));
// set up for next loop
i = j + 1;
}
}
示例3: while
inline void Tokenize<tstring, tstring>( const tstring& str, std::vector< tstring >& tokens, const tstring& delimiters )
{
// Skip delimiters at beginning.
tstring::size_type lastPos = str.find_first_not_of( delimiters, 0 );
// Find first "non-delimiter".
tstring::size_type pos = str.find_first_of( delimiters, lastPos );
while ( tstring::npos != pos || tstring::npos != lastPos )
{
// Add the token to the vector
tokens.push_back( str.substr( lastPos, pos - lastPos ) );
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of( delimiters, pos );
// Find next "non-delimiter"
pos = str.find_first_of( delimiters, lastPos );
}
}
示例4: trim
tstring trim(const tstring &tstr, const tstring& trimChars)
{
size_t s = tstr.find_first_not_of(trimChars);
size_t e = tstr.find_last_not_of (trimChars);
if ((tstring::npos == s) || ( tstring::npos == e))
return _T("");
else
return tstr.substr(s, e - s + 1);
}
示例5: Tokenize
inline void Tokenize( const tstring& str, std::map< TKey, TVal >& tokens, const tstring& delimiters )
{
// Skip delimiters at beginning.
tstring::size_type lastPos = str.find_first_not_of( delimiters, 0 );
// Find first "non-delimiter".
tstring::size_type pos = str.find_first_of( delimiters, lastPos );
while ( tstring::npos != pos || tstring::npos != lastPos )
{
tstringstream kStream( str.substr( lastPos, pos - lastPos ) );
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of( delimiters, pos );
// Find next "non-delimiter"
pos = str.find_first_of( delimiters, lastPos );
if ( tstring::npos != pos || tstring::npos != lastPos )
{
tstringstream vStream( str.substr( lastPos, pos - lastPos ) );
// At this point, we have the key and value. Build the map entry.
// Note that the stream operator stops at spaces.
TKey k;
kStream >> k;
TVal v;
vStream >> v;
tokens.insert( std::map< TKey, TVal >::value_type( k, v ) );
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of( delimiters, pos );
// Find next "non-delimiter"
pos = str.find_first_of( delimiters, lastPos );
}
else
{
示例6: trim
void trim(tstring& str, char ch)
{
tstring::size_type pos = str.find_first_not_of(ch);
if (pos == tstring::npos)
{
str = _T("");
return;
}
tstring::size_type pos2 = str.find_last_not_of(ch);
if (pos2 != tstring::npos)
{
str = str.substr(pos, pos2 - pos + 1);
}
else
{
str = str.substr(pos);
}
}
示例7: arguments
/*!
Splits \a cmd into list of arguments (space-separated).
*/
vector<tstring> CommandParser::splitCommand(const tstring & cmd)
{
tstring space = _T(" \t\f\v\n\r");
vector<tstring> args;
size_t space_pos = 0, start_pos = 0;
while (true) {
space_pos = cmd.find_first_of(space, start_pos);
if (space_pos == tstring::npos) {
args.push_back(cmd.substr(start_pos, cmd.length() - start_pos));
break;
} else {
args.push_back(cmd.substr(start_pos, space_pos - start_pos));
}
start_pos = cmd.find_first_not_of(space, space_pos);
}
return args;
}
示例8: ParseAttributes
void Script::ParseAttributes(tstring& attributes, Control* control)
{
INSPECT_SCOPE_TIMER( ("Attributes Script Attribute Processing") );
size_t pos = 0;
size_t end = tstring::npos;
while (pos < attributes.length() && pos != tstring::npos)
{
// eat ws
pos = attributes.find_first_not_of(LS_WHITESPACE, pos);
// the rest is WS, abort
if (pos == tstring::npos)
break;
// search for end of keyword
end = attributes.find_first_of(LS_WHITESPACE TXT( "=" ), pos);
// we have no symbol term, just abort
if (end == tstring::npos)
break;
// copy just our symbol into a string
tstring key (attributes.data() + pos, end - pos);
// next tchar
pos = end+1;
// eat ws
pos = attributes.find_first_not_of(LS_WHITESPACE, pos);
// the rest is WS, abort
if (pos == tstring::npos)
break;
// see if the value is directly quoted
size_t startQuote = attributes.find_first_of( TXT( "\"" ), pos);
size_t endQuote = attributes.find_first_of( TXT( "\"" ), startQuote+1);
// search for end of keyword
end = attributes.find_first_of( TXT( ";" ), pos);
// if the semi is in the quote
if (startQuote != tstring::npos && endQuote != tstring::npos && startQuote < end && end < endQuote)
{
// search for end of value not quoted
end = attributes.find_first_of( TXT( ";" ), endQuote);
}
// we have no symbol term, just abort
if (end == tstring::npos)
{
end = attributes.length();
}
// copy just our symbol into a string
tstring value (attributes.data() + pos, end - pos);
// next tchar
pos = end+1;
// trim quoted values
{
size_t start = value.find_first_of('\"');
size_t finish = value.find_last_of('\"');
if (start != tstring::npos)
{
if (start == finish)
{
value.erase(start, 1);
}
else if (start < finish)
{
value = value.substr(start + 1, finish - start - 1);
}
}
}
// insert
control->Process(key, value);
}
}
示例9: TriToken
tstring TriToken(tstring& Token){
tstring::size_type begin = Token.find_first_not_of(_T(' '));
if(begin == string::npos)return Token;
tstring::size_type end = Token.find_last_not_of(_T(' '));
return Token.substr(begin,end-begin+1);
}