abstract class CSV2::Lexer
- CSV2::Lexer
- Reference
- Object
Overview
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 = CSV2::Lexer.new "one,two\nthree"
lexer.next_token # => CSV2::Token(@kind=Cell, @value="one")
lexer.next_token # => CSV2::Token(@kind=Cell, @value="two")
lexer.next_token # => CSV2::Token(@kind=Newline, @value="two")
lexer.next_token # => CSV2::Token(@kind=Cell, @value="three")
lexer.next_token # => CSV2::Token(@kind=Eof, @value="three")
Defined in:
csv/lexer.crConstructors
-
.new(string : String, separator = DEFAULT_SEPARATOR, quote_char = DEFAULT_QUOTE_CHAR)
Creates a CSV lexer from a
String
. -
.new(io : IO, separator = DEFAULT_SEPARATOR, quote_char = DEFAULT_QUOTE_CHAR)
Creates a CSV lexer from an
IO
.
Instance Method Summary
-
#next_token
Returns the next
Token
in this CSV. - #quote_char : Char
-
#rewind
Rewinds this lexer to its beginning.
- #separator : Char
-
#token : Token
Returns the current
Token
.
Constructor Detail
Creates a CSV lexer from a String
.
Creates a CSV lexer from an IO
.