Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
		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);
			}
		}
    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;
    }
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());
}
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }