Skip to content

Commit

Permalink
Move out repeat handling from main code
Browse files Browse the repository at this point in the history
  • Loading branch information
moyner committed Jan 29, 2024
1 parent 691df67 commit bb0da6d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/InputParser/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,9 @@ function parse_deck_vector(f, T = Float64)
sizehint!(out, n)
for split_rec in record_lines
for el in split_rec
if occursin('*', el)
n_rep, el = split(el, '*')
n_rep = parse(Int, n_rep)
else
n_rep = 1
end
parsed = parse(T, el)::T
el, n_rep = handle_repeats(el)
parsed = Parsers.parse(T, el)
parsed::T
for i in 1:n_rep
push!(out, parsed)
end
Expand All @@ -234,6 +230,17 @@ function parse_deck_vector(f, T = Float64)
return out
end

function handle_repeats(el::String)
if occursin('*', el)
n_rep, el = split(el, '*')
el = String(el)
n_rep = Parsers.parse(Int, n_rep)
else
n_rep = 1
end
(el, n_rep)::Tuple{String, Int}
end

function skip_record(f)
rec = read_record(f)
while length(rec) > 0
Expand Down

0 comments on commit bb0da6d

Please sign in to comment.