csv

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package csv is the "encoding/csv" host module. See std/encoding/register.go for why this and its eight siblings each get their own leaf package instead of living in std's flat root, and how this directory's Module reaches the rest of magus without std importing back down to collect it.

Index

Constants

This section is empty.

Variables

View Source
var Module = std.Module{
	Name: "csv",
	WASM: true,
	Path: "encoding/csv",
	Doc:  "Delimiter-separated tabular text (CSV, TSV) parsing and rendering.",
	Methods: []std.Method{
		{
			Name: "parse",
			Doc:  "Parse delimiter-separated text into a list of rows, each a list of fields. Quoted fields, embedded delimiters, and embedded newlines are handled per RFC 4180. delimiter defaults to \",\" - pass \"\\t\" for TSV. When comment is a single character, lines starting with it are skipped. Raises when a row has a different field count than the first, which is the corruption a hand-rolled split would silently pass through.",
			Args: []std.Arg{
				{Name: "s", Type: std.TypeString},
				{Name: "delimiter", Type: std.TypeString, Optional: true, Default: ","},
				{Name: "comment", Type: std.TypeString, Optional: true},
			},
			Returns: []std.Ret{{Type: std.TypeStringSliceSlice}},
			Raises:  true,
			Impl:    CSVParse,
		},
		{
			Name: "stringify",
			Doc:  "Render rows (a list of lists of fields) as delimiter-separated text, quoting any field that needs it. delimiter defaults to \",\". The output ends with a newline, so it is ready to write.",
			Args: []std.Arg{
				{Name: "rows", Type: std.TypeStringSliceSlice},
				{Name: "delimiter", Type: std.TypeString, Optional: true, Default: ","},
			},
			Returns: []std.Ret{{Type: std.TypeString}},
			Raises:  true,
			Impl:    CSVStringify,
		},
	},
}

Module is the "encoding/csv" host module: delimiter-separated tabular text, in and out. Nothing in Buzz or in magus could read a table before this - a magusfile handed a coverage export, a dependency inventory, or any tool's --format=csv output had to split on commas by hand, which is wrong the moment a field is quoted or contains the delimiter.

TSV is this module with delimiter set to a tab rather than a separate module: the format differs by one character and nothing else, so a second name would be two things to learn for one behavior.

The options are ORDINARY OPTIONAL ARGUMENTS, not an opts map. Most of the stdlib's older methods take {str: any} bags, which means a misspelled key is silent; a declared argument is checked. New surface should not add to that.

Functions

func CSVParse

func CSVParse(_ context.Context, s, delimiter, comment string) ([][]string, error)

CSVParse parses delimiter-separated text into rows of fields.

func CSVStringify

func CSVStringify(_ context.Context, rows [][]string, delimiter string) (string, error)

CSVStringify renders rows as delimiter-separated text.

func Modules

func Modules() []std.Module

Modules returns this directory's contribution to the encoding module set. See std/encoding/register.go: it aggregates every leaf's Modules() into one slice, which is how a module here reaches std.All()'s callers without std importing this package to collect it.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL