Module std::encoding::csv

CSV parsing โ€” pure Hew implementation.

Parse CSV data from strings or files into a table that can be queried by row/column index or column name.

Examples

import std::encoding::csv;

fn main() {
    let table = csv.parse("name,age\nAlice,30\nBob,25");
    let rows = table.rows();
    let name = table.get_by_name(0, "name");
    println(name);  // "Alice"
}

Contents

Functions

Function parse

pub fn parse(data: String) -> Table

Parse CSV data from a string (first row is treated as headers).

Function parse_no_headers

pub fn parse_no_headers(data: String) -> Table

Parse CSV data from a string without treating the first row as headers.

Function parse_file

pub fn parse_file(path: String) -> Table

Parse CSV data from a file path (first row is treated as headers).

Panics if the file cannot be read.

Function parse_impl

fn parse_impl(data: String, has_headers: bool) -> Table

Parse CSV data with optional header row handling.

Function parse_csv_line

fn parse_csv_line(line: String) -> Vec<String>

Parse a single CSV line into fields, handling quoted fields.

Function find_header

fn find_header(headers: Vec<String>, name: String) -> i32

Find the column index for a header name. Returns -1 if not found.

Types

Struct Table

A parsed CSV table with headers and data rows.

Fields

hdrs: Vec<String>
data: Vec<Vec<String>>

Traits

Trait TableMethods

Methods available on a CSV Table.

Methods

fn rows(self: Table) -> i32 fn cols(self: Table) -> i32 fn header(self: Table, col: i32) -> String fn get(self: Table, row: i32, col: i32) -> String fn get_by_name(self: Table, row: i32, col_name: String) -> String fn free(self: Table)