CSV::Lexer

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

Class Method Summary

Instance Method Summary

Class Method 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

abstract def rewindSource

Rewinds this lexer to its beginning.

def separator : CharSource

def token : TokenSource

Returns the current Token.

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

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部