From 88d19f5de979ec0a91b642328a11b54c19601847 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 25 Dec 2023 10:28:50 -0800 Subject: [PATCH] Cleanup scan --- test/scan.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/scan.h b/test/scan.h index 9ea3f48e..212d1844 100644 --- a/test/scan.h +++ b/test/scan.h @@ -51,11 +51,9 @@ class scan_buffer { : ptr_(ptr), end_(end), contiguous_(contiguous) {} ~scan_buffer() = default; - auto is_empty() const -> bool { return ptr_ == end_; } - - void set(const char* ptr, const char* end) noexcept { - ptr_ = ptr; - end_ = end; + void set(string_view buf) { + ptr_ = buf.begin(); + end_ = buf.end(); } auto ptr() const -> const char* { return ptr_; } @@ -128,12 +126,12 @@ class scan_buffer { if (ptr == it.buf_->end_) it.ptr_ = iterator::sentinel(); } - auto begin() noexcept -> iterator { return this; } - auto end() noexcept -> iterator { return {}; } + auto begin() -> iterator { return this; } + auto end() -> iterator { return {}; } auto is_contiguous() const -> bool { return contiguous_; } - // Tries consuming a single code unit. + // Tries consuming a single code unit. Returns true iff there is more input. auto try_consume() -> bool { FMT_ASSERT(ptr_ != end_, ""); ++ptr_; @@ -252,7 +250,7 @@ class file_scan_buffer : public scan_buffer { if (c != EOF) file_.unget(static_cast(c)); buf = file_.buffer(); } - set(buf.begin(), buf.end()); + set(buf); } void consume() override {