From 4863409601905c9a6b4474c4ecf2a2e6bdeff9cc Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Thu, 27 Jun 2024 20:55:37 +0100 Subject: [PATCH] re #440: simplify LineContents::reset_with_next_line(substr buf, size_t offset) --- src/c4/yml/parser_state.hpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/c4/yml/parser_state.hpp b/src/c4/yml/parser_state.hpp index b1bcfdd6..1977cbf5 100644 --- a/src/c4/yml/parser_state.hpp +++ b/src/c4/yml/parser_state.hpp @@ -58,30 +58,27 @@ struct LineContents void reset_with_next_line(substr buf, size_t offset) { RYML_ASSERT(offset <= buf.len); - char const* C4_RESTRICT b = &buf[offset]; - char const* C4_RESTRICT e = b; + size_t e = offset; // get the current line stripped of newline chars - while(e < buf.end() && (*e != '\n' && *e != '\r')) + while(e < buf.len && (buf.str[e] != '\n' && buf.str[e] != '\r')) ++e; - RYML_ASSERT(e >= b); - const substr stripped_ = buf.sub(offset, static_cast(e - b)); + RYML_ASSERT(e >= offset); + const substr stripped_ = buf.range(offset, e); // advance pos to include the first line ending - if(e != buf.end() && *e == '\r') + if(e < buf.len && buf.str[e] == '\r') ++e; - if(e != buf.end() && *e == '\n') + if(e < buf.len && buf.str[e] == '\n') ++e; - RYML_ASSERT(e >= b); - const substr full_ = buf.sub(offset, static_cast(e - b)); + const substr full_ = buf.range(offset, e); reset(full_, stripped_); } void reset(substr full_, substr stripped_) { + rem = stripped_; + indentation = stripped_.first_not_of(' '); // find the first column where the character is not a space full = full_; stripped = stripped_; - rem = stripped_; - // find the first column where the character is not a space - indentation = stripped.first_not_of(' '); } C4_ALWAYS_INLINE size_t current_col() const RYML_NOEXCEPT