abstract class CSV2::Lexer

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(string : String, separator = DEFAULT_SEPARATOR, quote_char = DEFAULT_QUOTE_CHAR) #

Creates a CSV lexer from a String.


[View source]
def self.new(io : IO, separator = DEFAULT_SEPARATOR, quote_char = DEFAULT_QUOTE_CHAR) #

Creates a CSV lexer from an IO.


[View source]

Instance Method Detail

def next_token #

Returns the next Token in this CSV.


[View source]
def quote_char : Char #

[View source]
abstract def rewind #

Rewinds this lexer to its beginning.


[View source]
def separator : Char #

[View source]
def token : Token #

Returns the current Token.


[View source]