本文整理汇总了C++中std::basic_string::find_first_not_of方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::find_first_not_of方法的具体用法?C++ basic_string::find_first_not_of怎么用?C++ basic_string::find_first_not_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_string
的用法示例。
在下文中一共展示了basic_string::find_first_not_of方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sp
std::basic_string<Ch> encode_char_entities(const std::basic_string<Ch> &s)
{
// Don't do anything for empty strings.
if(s.empty()) return s;
typedef typename std::basic_string<Ch> Str;
Str r;
// To properly round-trip spaces and not uglify the XML beyond
// recognition, we have to encode them IF the text contains only spaces.
Str sp(1, Ch(' '));
if(s.find_first_not_of(sp) == Str::npos) {
// The first will suffice.
r = detail::widen<Ch>(" ");
r += Str(s.size() - 1, Ch(' '));
} else {
typename Str::const_iterator end = s.end();
for (typename Str::const_iterator it = s.begin(); it != end; ++it)
{
switch (*it)
{
case Ch('<'): r += detail::widen<Ch>("<"); break;
case Ch('>'): r += detail::widen<Ch>(">"); break;
case Ch('&'): r += detail::widen<Ch>("&"); break;
case Ch('"'): r += detail::widen<Ch>("""); break;
case Ch('\''): r += detail::widen<Ch>("'"); break;
default: r += *it; break;
}
}
}
return r;
}
示例2: lstrip
static inline std::basic_string<_CharT, _Traits, _Alloc> lstrip(
const std::basic_string<_CharT, _Traits, _Alloc> &a,
const strip_t stripchars) {
typedef std::basic_string<_CharT, _Traits, _Alloc> str_t;
typename str_t::size_type p = a.find_first_not_of(stripchars);
if (p == str_t::npos) return "";
return a.substr(p);
}
示例3:
//@todo test
template<typename TARGET, typename charT, typename traits> std::list<TARGET>
stringToList( const std::basic_string<charT, traits> &source, charT separator )
{
std::list<TARGET> ret;
for (
size_t next = source.find_first_not_of( separator );
next != std::string::npos;
next = source.find_first_not_of( separator, next )
) {
const size_t start = next;
next = source.find( separator, start );
ret.push_back( boost::lexical_cast<TARGET>( source.substr( start, next - start ) ) );
}
return ret;
}
示例4: trim
template<typename char_t> std::basic_string<char_t> trim(const std::basic_string<char_t>& what)
{
if ( what.empty() ) return what;
const char_t whitespace[3] = { char_t(' '), char_t('\t'), 0 };
size_t left = what.find_first_not_of(whitespace);
size_t right = what.find_last_not_of(whitespace);
if ( left == std::basic_string<char_t>::npos )
{
return std::basic_string<char_t>();
}
else
{
return what.substr(left, right-left+1);
}
}
示例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();
}
}
}
}
示例6: 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());
}