当前位置: 首页>>代码示例>>C++>>正文


C++ basic_string::find_first_not_of方法代码示例

本文整理汇总了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>("&#32;");
            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>("&lt;"); break;
                    case Ch('>'): r += detail::widen<Ch>("&gt;"); break;
                    case Ch('&'): r += detail::widen<Ch>("&amp;"); break;
                    case Ch('"'): r += detail::widen<Ch>("&quot;"); break;
                    case Ch('\''): r += detail::widen<Ch>("&apos;"); break;
                    default: r += *it; break;
                }
            }
        }
        return r;
    }
开发者ID:grantbrown,项目名称:PDAL,代码行数:31,代码来源:xml_parser_utils.hpp

示例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);
 }
开发者ID:DarkOfTheMoon,项目名称:Carve,代码行数:8,代码来源:stringfuncs.hpp

示例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;
}
开发者ID:Rollmops,项目名称:isis,代码行数:18,代码来源:common.hpp

示例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);
		}
	}
开发者ID:basmith,项目名称:BearLibTerminal,代码行数:17,代码来源:Utility.hpp

示例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();
                }
            }
        }
    }
开发者ID:ZhouCS,项目名称:libvot,代码行数:41,代码来源:io_utils.cpp

示例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());
}
开发者ID:arlen7772gg,项目名称:NIM_Duilib_Framework,代码行数:21,代码来源:string_util.cpp


注:本文中的std::basic_string::find_first_not_of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。