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")
Creates a CSV lexer from a String
.
Creates a CSV lexer from an IO
.
Returns the next Token
in this CSV.
Rewinds this lexer to the beginning
Returns the current Token
.
Reference
Reference
Object
Object
Creates a CSV lexer from a String
.
Creates a CSV lexer from an IO
.
Rewinds this lexer to the beginning
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/CSV/Lexer.html