本文整理汇总了C++中std::basic_string::find_first_of方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::find_first_of方法的具体用法?C++ basic_string::find_first_of怎么用?C++ basic_string::find_first_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_string
的用法示例。
在下文中一共展示了basic_string::find_first_of方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split_by_tokens
ResultList split_by_tokens(const std::basic_string<CharT> &s,
const std::basic_string<CharT> &tokens, bool keepEmptyParts = true)
{
if (tokens.length() == 1)
return split<ResultList>(s, tokens, keepEmptyParts);
ResultList slist;
typename std::basic_string<CharT>::size_type start = 0;
typename std::basic_string<CharT>::size_type pos;
std::basic_string<CharT> part;
// If delimiter.empty():
// pos = s.find_first_of(delimiter, start);
// pos will be s.npos.
while ((pos = s.find_first_of(tokens, start)) != s.npos) { // strtok
part = s.substr(start, pos - start);
if (!part.empty() || keepEmptyParts)
slist.push_back(part);
start = pos + 1;
}
if (start != s.length() || keepEmptyParts)
slist.push_back(s.substr(start));
return slist;
}
示例2: node_select_piece
explicit node_select_piece(const std::basic_string<char_type>& str)
: tag(), type(specifier_type::none_), attr()
{
auto f1 = std_future::overload(
[](const std::string& str) { return str.find_first_of("#."); },
[](const std::wstring& str) { return str.find_first_of(L"#."); }
);
const auto split_pos = f1(str);
if (basic_string<char_type>::npos == split_pos) {
tag = str;
}
else {
auto is_sharp = std_future::overload(
[](const char c) { return '#' == c; },
[](const wchar_t c) { return L'#' == c; }
);
tag = str.substr(0, split_pos);
type = (is_sharp(str[split_pos])) ? specifier_type::id_ : specifier_type::class_;
attr = str.substr(split_pos + 1);
}
}
示例3: if
std::vector< std::basic_string< CharType > > str_split( std::basic_string< CharType > const & p_str, std::basic_string< CharType > const & p_delims, uint32_t p_maxSplits, bool p_bKeepVoid )
{
typedef std::basic_string< CharType > string_t;
std::vector< string_t > l_arrayReturn;
if ( ! p_str.empty() && ! p_delims.empty() && p_maxSplits > 0 )
{
l_arrayReturn.reserve( p_maxSplits + 1 );
std::size_t l_numSplits = 0;
std::size_t l_pos = 0;
std::size_t l_start = 0;
do
{
l_pos = p_str.find_first_of( p_delims, l_start );
if ( l_pos == l_start )
{
l_start = l_pos + 1;
if ( p_bKeepVoid )
{
l_arrayReturn.push_back( string_t() );
}
}
else if ( l_pos == string_t::npos || l_numSplits == p_maxSplits )
{
string_t remnants = p_str.substr( l_start );
if ( !remnants.empty() || p_bKeepVoid )
{
l_arrayReturn.push_back( remnants );
}
return l_arrayReturn;
}
else
{
l_arrayReturn.push_back( p_str.substr( l_start, l_pos - l_start ) );
l_start = l_pos + 1;
}
//l_start = p_str.find_first_not_of( p_delims, l_start );
++ l_numSplits;
}
while ( l_pos != string_t::npos );
}
return l_arrayReturn;
}
示例4: StringTokenizeT
int StringTokenizeT(const std::basic_string<CharType> &input,
const std::basic_string<CharType> &delimitor,
std::list<std::basic_string<CharType> > &output)
{
size_t token_begin;
size_t token_end;
output.clear();
for (token_begin = token_end = 0; token_end != std::basic_string<CharType>::npos;)
{
token_begin = input.find_first_not_of(delimitor, token_begin);
if (token_begin == std::basic_string<CharType>::npos)
break;
token_end = input.find_first_of(delimitor, token_begin + 1);
output.push_back(input.substr(token_begin, token_end - token_begin));
token_begin = token_end + 1;
}
return static_cast<int>(output.size());
}
示例5: is_simple_data
bool is_simple_data(const std::basic_string<Ch> &data)
{
const static std::basic_string<Ch> chars = convert_chtype<Ch, char>(" \t{};\n\"");
return !data.empty() && data.find_first_of(chars) == data.npos;
}
示例6: is_simple_key
bool is_simple_key(const std::basic_string<Ch> &key)
{
const static std::basic_string<Ch> chars = convert_chtype<Ch, char>(" \t{};\n\"");
return !key.empty() && key.find_first_of(chars) == key.npos;
}