class

CSV::Lexer

Inherits Reference / Object

A CSV lexer lets you consume a CSV token by token. You can use this to efficiently parse a CSV without the need to allocate intermediate arrays.

require "csv"

lexer = CSV::Lexer.new "one,two\nthree"
lexer.next_token # => CSV::Token(@kind=Cell, @value="one")
lexer.next_token # => CSV::Token(@kind=Cell, @value="two")
lexer.next_token # => CSV::Token(@kind=Newline, @value="two")
lexer.next_token # => CSV::Token(@kind=Cell, @value="three")
lexer.next_token # => CSV::Token(@kind=Eof, @value="three")

Constructors

new(string : String, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR) : self

Creates a CSV lexer from a String.

Source
new(io : IO, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR) : self

Creates a CSV lexer from an IO.

Source

Instance methods

next_token

Returns the next Token in this CSV.

Source
quote_char
Source
rewind

Rewinds this lexer to the beginning

Source
separator
Source
token

Returns the current Token.

Source