From 065fad0c59cfce2e8ac3fa001368912abe7c5743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ama=C3=ABl=20Obliger?= Date: Thu, 17 Oct 2024 00:27:21 +0200 Subject: [PATCH] Update LineReader.jl Add length, lastindex and getindex to Line struct. --- src/LineReader.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/LineReader.jl b/src/LineReader.jl index fa03d55..a39a404 100644 --- a/src/LineReader.jl +++ b/src/LineReader.jl @@ -21,6 +21,16 @@ function Base.getindex(l::Line, index::Int64) error("Index out of range") end +function Base.length(l::Line) + len = 0 + for (i,) in enumerate(l) + len += 1 + end + return len +end + +Base.lastindex(l::Line) = length(l) +Base.getindex(l::Line, I) = [l[i] for i in I] function find_delimiter(line::Bview, delimiter::UInt8, state::Int) # State refers to the last location we scanned @@ -55,4 +65,4 @@ end @inline function splitV(line::Sview, delimiter::Char) length(line) > 0 || error("Empty line given") return Line(line.data, UInt8(delimiter)) -end \ No newline at end of file +end