From f57d23fef04009f03e329601e1eecafb01b79d5e Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 6 Aug 2024 10:36:21 -0400 Subject: [PATCH] xo-tokenizer: feat: + span.from_cstr() --- include/xo/tokenizer/span.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/xo/tokenizer/span.hpp b/include/xo/tokenizer/span.hpp index 00f8cf74..e53bc18e 100644 --- a/include/xo/tokenizer/span.hpp +++ b/include/xo/tokenizer/span.hpp @@ -24,6 +24,14 @@ namespace xo { /** @brief create span for the contiguous memory range [@p lo, @p hi) **/ span(CharT * lo, CharT * hi) : lo_{lo}, hi_{hi} {} + /** @brief create span for C-style string @p cstr **/ + static span from_cstr(const CharT * cstr) { + CharT * lo = cstr; + CharT * hi = cstr ? cstr + strlen(cstr) : nullptr; + + return span(lo, hi); + } + ///@{ /** @name getters **/