ctpg icon indicating copy to clipboard operation
ctpg copied to clipboard

string_view buffer

Open mjhurd opened this issue 4 years ago • 1 comments

Thanks for your work! I'm enjoying playing with the library.

I found this handy fwiw:

struct sv_buffer
{
public:
    constexpr sv_buffer(std::string_view str) : str(str) {}
    constexpr sv_buffer(const char *str) : str(str) {}

    constexpr auto begin() const { return str.cbegin(); }
    constexpr auto end() const { return str.cend(); }

    using iterator = std::string_view::const_iterator;

    constexpr std::string_view get_view(iterator start, iterator end) const
    {
        return std::string_view(str.data() + (start - str.begin()),
                                end - start);
    }

private:
    std::string_view str;
};

mjhurd avatar Jan 27 '22 03:01 mjhurd

You are welcome! You can prepare a PR with this if you want. Name it string_view_buffer though.

peter-winter avatar Jan 27 '22 11:01 peter-winter

Merged with https://github.com/peter-winter/ctpg/pull/74

peter-winter avatar Feb 06 '24 09:02 peter-winter