diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-10-22 01:25:00 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-22 01:25:00 -0600 |
| commit | 3d0c8accb95166f786fbcf3801c679b13042523b (patch) | |
| tree | cb7a97db5d741e74a30e68d53d2a91df272ff6e8 /lib | |
| parent | 939fdf4a89022d484dbc6650cee901d75a3a8550 (diff) | |
resolves #4368 redo loop rather than using recursion to locate next line to process (PR #4372)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/asciidoctor/reader.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb index d74fbd23..c101fd9d 100644 --- a/lib/asciidoctor/reader.rb +++ b/lib/asciidoctor/reader.rb @@ -129,16 +129,20 @@ class Reader # Returns the next line of the source data as a String if there are lines remaining. # Returns nothing if there is no more data. def peek_line direct = false - if direct || @look_ahead > 0 - @unescape_next_line ? ((line = @lines[-1]).slice 1, line.length) : @lines[-1] - elsif @lines.empty? - @look_ahead = 0 - nil - else - # FIXME the problem with this approach is that we aren't - # retaining the modified line (hence the @unescape_next_line tweak) - # perhaps we need a stack of proxied lines - (process_line @lines[-1]) || peek_line + while true + next_line = @lines[-1] + return @unescape_next_line ? (next_line.slice 1, next_line.length) : next_line if direct || @look_ahead > 0 + if next_line + # FIXME the problem with this approach is that we aren't + # retaining the modified line (hence the @unescape_next_line tweak) + # perhaps we need a stack of proxied lines + if (line = process_line next_line) + return line + end + else + @look_ahead = 0 + return + end end end |
