W3cubDocs

/Crystal

abstract class CSV::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 = 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")

Defined in:

csv/lexer.cr

Constructors

Instance Method Summary

Constructor Detail

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

Creates a CSV lexer from a String.

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

Creates a CSV lexer from an IO.

Instance Method Detail

def next_tokenSource

Returns the next Token in this CSV.

def quote_char : CharSource

def rewindSource

Rewinds this lexer to the beginning

def separator : CharSource

def token : TokenSource

Returns the current Token.

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/CSV/Lexer.html