Skip to content

Dialect

TynK-M edited this page Aug 24, 2026 · 1 revision

Dialect

Dialect defines the formatting rules used when parsing CSV data.

A dialect controls the field separator, quote character, and line-ending convention.

Definition

pub const Dialect = struct {
    separator: u8 = ',',
    quote: u8 = '"',
    line_ending: LineEnding = .lf,
};

Fields

Field Type Default Description
separator u8 , Character separating fields
quote u8 " Character used to delimit quoted fields
line_ending LineEnding .lf Line-ending convention

Default dialect

Creating a Dialect without specifying any fields uses the standard defaults:

const dialect = Dialect{};

This is equivalent to:

const dialect = Dialect{
    .separator = ',',
    .quote = '"',
    .line_ending = .lf,
};

Custom dialects

Any field can be overridden when creating a dialect.

For example, a semicolon-separated format:

const dialect = Dialect{
    .separator = ';',
};

A tab-separated format:

const dialect = Dialect{
    .separator = '\t',
};

Multiple options can be configured together:

const dialect = Dialect{
    .separator = ';',
    .quote = '\'',
    .line_ending = .crlf,
};

Methods

isSeparator

pub fn isSeparator(self: *Dialect, c: u8) bool

Returns true when c is the configured field separator.

var dialect = Dialect{};

dialect.isSeparator(','); // true
dialect.isSeparator(';'); // false

isQuote

pub fn isQuote(self: *Dialect, c: u8) bool

Returns true when c is the configured quote character.

var dialect = Dialect{};

dialect.isQuote('"');  // true
dialect.isQuote('\''); // false

isLineEnding

pub fn isLineEnding(
    self: *Dialect,
    input: []const u8,
    pos: usize,
) bool

Checks whether a configured line ending starts at pos in input.

The bytes checked depend on the configured LineEnding:

Line ending Sequence
.lf \n
.cr \r
.crlf \r\n

For .crlf, both bytes must be present for the method to return true.

Built-in dialects

Zarko provides common dialect presets in dialects.zig.

See Built-in Dialects for:

  • excel
  • tsv
  • semicolon

Related

Documentation

API Reference

Guides

Clone this wiki locally