~/bend-docscommunity

lib.bend checks

raw source on the hub · import 0x36062a6887f9a7dac4ca208d99d96105/lib.bend as Lib

Csv — small, Base-only comma-separated values.

Rows are List<&2, String>; a document is List<&2, List<&2, String>>. The parser is deliberately a small line-oriented CSV subset. See README.

1 import
import Base

Types

type Csv.Scan source · line 26 · raw

Data

The scanner has an explicit state so doubled quotes need no mutual recursion. AfterQuote re-processes the next non-quote character as plain.

Definitions

def Csv.is_quote source · line 8 · raw

@+c:Char -> Bool

A field is quoted when it contains syntax which would otherwise be data.

def Csv.is_comma source · line 13 · raw

@+c:Char -> Bool

def Csv.parse_line.finish source · line 19 · raw

@+quoted:Bool -> @+field:String -> @+fields:List<&2, String> -> List<&2, String>

Finish a field. fields is stored backwards while scanning.

def Csv.parse_line.go source · line 31 · raw

@s:String -> @state:Csv.Scan -> @+field:String -> @+fields:List<&2, String> -> List<&2, String>

def Csv.parse_line source · line 70 · raw

@s:String -> List<&2, String>

Parse one physical line. Empty lines are one empty field.

def Csv.parse.go source · line 73 · raw

@lines:List<&2, String> -> List<&2, List<&2, String>>

def Csv.parse source · line 84 · raw

@s:String -> List<&2, List<&2, String>>

Empty input is no document; a non-empty input is split on LF. CR is not stripped, so callers wanting CRLF should trim it before parsing.

def Csv.encode_field.escaped source · line 92 · raw

@s:String -> String

Double quotes in a quoted field are represented by two quotes.

def Csv.encode_field source · line 104 · raw

@+s:String -> String

def Csv.encode_row.go source · line 112 · raw

@cells:List<&2, String> -> @first:Bool -> String

def Csv.encode_row source · line 126 · raw

@cells:List<&2, String> -> String

def Csv.encode.go source · line 129 · raw

@rows:List<&2, List<&2, String>> -> @first:Bool -> String

def Csv.encode source · line 143 · raw

@rows:List<&2, List<&2, String>> -> String