src/rconv/private/line_reader

  Source   Edit

Types

LineReader = object of RootObj
  str: string                ## The string it's reading
  len: int                   ## Total length of the string
  cursor: int                ## Byte offset where the reader left off
  line: int                  ## Current line it's on
  col: int                   ## Current column it's on
  
A LineReader simply reads over the provided string and retutns stripped lines until all lines have been read.   Source   Edit

Procs

func newLineReader(str: string): LineReaderRef {....raises: [], tags: [].}
Creates a new LineReader instance from the given string   Source   Edit

Methods

method col(this: LineReaderRef): int {.base, inline, noSideEffect, ...raises: [],
                                       tags: [].}
Returns the column number where the reader is currently on   Source   Edit
method isEOF(this: LineReaderRef): bool {.base, inline, noSideEffect,
    ...raises: [], tags: [].}
Returns if the LineReader has reached the end and can't produce any more lines   Source   Edit
method line(this: LineReaderRef): int {.base, inline, noSideEffect, ...raises: [],
                                        tags: [].}
Returns the line number where the reader is currently on   Source   Edit
method nextLine(this: LineReaderRef): string {.base, ...raises: [], tags: [].}
Reads the next line without trailing whitespaces Skips empty lines all together

Example:

let reader = newLineReader("line1\n \t \nline2\n  without whitespace   ")
assert reader.nextLine == "line1"
assert reader.nextLine == "line2"
assert reader.nextLine == "without whitespace"
  Source   Edit
method reset(this: LineReaderRef): void {.base, ...raises: [], tags: [].}
Resets the LineReader to the beginning   Source   Edit