Exemple #1
0
static inline
void SplitStringToIteratorUsing(const StringPiece& full, const char* delim, ITR& result)
{
    // Optimize the common case where delim is a single character.
    if (delim[0] != '\0' && delim[1] == '\0')
    {
        char c = delim[0];
        const char* p = full.data();
        const char* end = p + full.size();
        while (p != end)
        {
            if (*p == c)
                ++p;
            else
            {
                const char* start = p;
                while (++p != end && *p != c) {}
                *result++ = StringType(start, p - start);
            }
        }
        return;
    }

    std::string::size_type begin_index, end_index;
    begin_index = full.find_first_not_of(delim);
    while (begin_index != std::string::npos)
    {
        end_index = full.find_first_of(delim, begin_index);
        if (end_index == std::string::npos)
        {
            *result++ = full.substr(begin_index).as_string();
            return;
        }
        *result++ = full.substr(begin_index, (end_index - begin_index)).as_string();
        begin_index = full.find_first_not_of(delim, end_index);
    }
}
Exemple #2
0
	bool ContainsOnlyChars(const StringPiece& input,
		const StringPiece& characters) {
		return input.find_first_not_of(characters) == StringPiece::npos;
	}