Parser

public struct Parser

A parser for streaming CSV data.

Note

You should create a new Parser instance for each CSV document you parse.
  • The type of handler that gets called when a header is parsed.

    Declaration

    Swift

    public typealias HeaderHandler = (_ title: [UInt8])throws -> ()

    Parameters

    title

    The data for the header that is parsed.

  • The type of handler that gets called when a cell is parsed.

    Declaration

    Swift

    public typealias CellHandler = (_ title: [UInt8], _ contents: [UInt8])throws -> ()

    Parameters

    title

    The header for the cell that is parsed.

    contents

    The data for the cell that is parsed.

  • The callback that is called when a header is parsed.

    Declaration

    Swift

    public var onHeader: HeaderHandler?
  • The callback that is called when a cell is parsed.

    Declaration

    Swift

    public var onCell: CellHandler?
  • The struct that configures parsing options

    Declaration

    Swift

    public var configuration: Config
  • Creates a new Parser instance.

    Declaration

    Swift

    public init(onHeader: HeaderHandler? = nil, onCell: CellHandler? = nil, configuration: Config = Config.default)

    Parameters

    onHeader

    The callback that will be called when a header is parsed.

    onCell

    The callback that will be called when a cell is parsed.

    configuration

    The struct that configures parsing options

  • Parses an arbitrary portion of a CSV document.

    The data passed in should be the next slice of the document directly after the previous one.

    When a header is parsed from the data, the data will be passed into the registered .onHeader callback. When a cell is parsed from the data, the header for that given cell and the cell’s data will be passed into the .onCell callback.

    Declaration

    Swift

    public mutating func parse(_ data: [UInt8], length: Int? = nil) -> Result<Void, ErrorList>

    Parameters

    data

    The portion of the CSV document to parse.

    length

    The full content length of the document that is being parsed.

    Return Value

    A Result instance that will have a .failure case with all the errors thrown from the registered callbacks. If there are no errors, then the result will be a .success case.