[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/nlitsme/cpputils/master/include/cpputils/string-lineenum.h [Back]  [Original]

#pragma once

#include 
#include 
/*
 *
 * enumerate lines in a byte / char range like this:
 *
 * for (auto line : lineenumerator(range))
 * {
 *    ...
 * }
 *
 * note that this is kind of a duplicate of stringsplitter
 */

// todo: fix problem where last non-lf terminated section is not
// returned as a part.
template
struct lineenumerator {
    struct iter {
        PTR p, q, last;

        iter(PTR first, PTR last)
            : p(first), q(first), last(last)
        {
            q = std::find(p, last, '\n');
        }
        auto operator*()
        {
            return std::string(p, q);
        }
        iter& operator++()
        {
            p = (q

Web Proxy Viewer  |  New URL  |  Original Page