lisette-stdlib 0.1.13

Little language inspired by Rust that compiles to Go
Documentation
// Generated by Lisette bindgen
// Source: encoding/csv (Go stdlib)
// Go: 1.25.5
// Lisette: 0.1.12

import "go:io"

pub fn NewReader(r: io.Reader) -> Ref<Reader>

pub fn NewWriter(w: io.Writer) -> Ref<Writer>

/// A ParseError is returned for parsing errors.
/// Line and column numbers are 1-indexed.
pub struct ParseError {
  pub StartLine: int,
  pub Line: int,
  pub Column: int,
  pub Err: error,
}

/// A Reader reads records from a CSV-encoded file.
/// 
/// As returned by [NewReader], a Reader expects input conforming to RFC 4180.
/// The exported fields can be changed to customize the details before the
/// first call to [Reader.Read] or [Reader.ReadAll].
/// 
/// The Reader converts all \r\n sequences in its input to plain \n,
/// including in multiline field values, so that the returned data does
/// not depend on which line-ending convention an input file uses.
pub struct Reader {
  pub Comma: int32,
  pub Comment: int32,
  pub FieldsPerRecord: int,
  pub LazyQuotes: bool,
  pub TrimLeadingSpace: bool,
  pub ReuseRecord: bool,
  pub TrailingComma: bool,
}

/// A Writer writes records using CSV encoding.
/// 
/// As returned by [NewWriter], a Writer writes records terminated by a
/// newline and uses ',' as the field delimiter. The exported fields can be
/// changed to customize the details before
/// the first call to [Writer.Write] or [Writer.WriteAll].
/// 
/// [Writer.Comma] is the field delimiter.
/// 
/// If [Writer.UseCRLF] is true,
/// the Writer ends each output line with \r\n instead of \n.
/// 
/// The writes of individual records are buffered.
/// After all data has been written, the client should call the
/// [Writer.Flush] method to guarantee all data has been forwarded to
/// the underlying [io.Writer].  Any errors that occurred should
/// be checked by calling the [Writer.Error] method.
pub struct Writer {
  pub Comma: int32,
  pub UseCRLF: bool,
}

/// These are the errors that can be returned in [ParseError.Err].
pub var ErrBareQuote: error

/// These are the errors that can be returned in [ParseError.Err].
pub var ErrFieldCount: error

/// These are the errors that can be returned in [ParseError.Err].
pub var ErrQuote: error

/// These are the errors that can be returned in [ParseError.Err].
pub var ErrTrailingComma: error

impl ParseError {
  fn Error(self: Ref<ParseError>) -> string

  fn Unwrap(self: Ref<ParseError>) -> Option<error>
}

impl Reader {
  /// FieldPos returns the line and column corresponding to
  /// the start of the field with the given index in the slice most recently
  /// returned by [Reader.Read]. Numbering of lines and columns starts at 1;
  /// columns are counted in bytes, not runes.
  /// 
  /// If this is called with an out-of-bounds index, it panics.
  fn FieldPos(self: Ref<Reader>, field: int) -> (int, int)

  /// InputOffset returns the input stream byte offset of the current reader
  /// position. The offset gives the location of the end of the most recently
  /// read row and the beginning of the next row.
  fn InputOffset(self: Ref<Reader>) -> int64

  /// Read reads one record (a slice of fields) from r.
  /// If the record has an unexpected number of fields,
  /// Read returns the record along with the error [ErrFieldCount].
  /// If the record contains a field that cannot be parsed,
  /// Read returns a partial record along with the parse error.
  /// The partial record contains all fields read before the error.
  /// If there is no data left to be read, Read returns nil, [io.EOF].
  /// If [Reader.ReuseRecord] is true, the returned slice may be shared
  /// between multiple calls to Read.
  fn Read(self: Ref<Reader>) -> Result<Slice<string>, error>

  /// ReadAll reads all the remaining records from r.
  /// Each record is a slice of fields.
  /// A successful call returns err == nil, not err == [io.EOF]. Because ReadAll is
  /// defined to read until EOF, it does not treat end of file as an error to be
  /// reported.
  fn ReadAll(self: Ref<Reader>) -> Result<Slice<Slice<string>>, error>
}

impl Writer {
  /// Error reports any error that has occurred during
  /// a previous [Writer.Write] or [Writer.Flush].
  fn Error(self: Ref<Writer>) -> Result<(), error>

  /// Flush writes any buffered data to the underlying [io.Writer].
  /// To check if an error occurred during Flush, call [Writer.Error].
  fn Flush(self: Ref<Writer>)

  /// Write writes a single CSV record to w along with any necessary quoting.
  /// A record is a slice of strings with each string being one field.
  /// Writes are buffered, so [Writer.Flush] must eventually be called to ensure
  /// that the record is written to the underlying [io.Writer].
  fn Write(self: Ref<Writer>, record: Slice<string>) -> Result<(), error>

  /// WriteAll writes multiple CSV records to w using [Writer.Write] and
  /// then calls [Writer.Flush], returning any error from the Flush.
  fn WriteAll(self: Ref<Writer>, records: Slice<Slice<string>>) -> Result<(), error>
}