Documentation
¶
Overview ¶
A CSV implementation inspired by Python's CSV module. Supports custom CSV formats.
Example (ReadingWriting) ¶
buf := bytes.Buffer{}
writer := csv.NewWriter(&buf)
writer.Write([]string{"Hello", "World", "!"})
writer.Flush()
reader := csv.NewReader(&buf)
columns, err := reader.Read()
if err != nil {
panic(err)
}
for _, s := range columns {
fmt.Println(s)
}
Output: Hello World !
Index ¶
Examples ¶
Constants ¶
const ( QuoteDefault QuoteMode = iota // See DefaultQuoting. QuoteAll = iota // Quotes around every field. QuoteMinimal = iota // Quotes when needed. QuoteNonNumeric = iota // Quotes around non-numeric fields. QuoteNonNumericNonEmpty = iota // Quotes around non-numeric or empty fields. // Never quote. Use with care. Could make things unparsable. QuoteNone = iota )
Values QuoteMode can take.
const ( DoubleQuoteDefault DoubleQuoteMode = iota // See DefaultDoubleQuote. DoDoubleQuote = iota // Escape using double escape characters. NoDoubleQuote = iota // Escape using escape character. )
Values DoubleQuoteMode can take.
const ( DefaultDelimiter = ',' DefaultQuoting = QuoteMinimal DefaultDoubleQuote = DoDoubleQuote DefaultEscapeChar = '\\' DefaultQuoteChar = '"' DefaultLineTerminator = "\n" DefaultComment = '#' )
Default dialect.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
type Dialect struct {
// The delimiter that separates each field from another. Defaults to
// DefaultDelimiter.
Delimiter rune
// What quoting mode to use. Defaults to DefaultQuoting.
Quoting QuoteMode
// How to escape quotes. Defaults to DefaultDoubleQuote.
DoubleQuote DoubleQuoteMode
// Character to use for escaping. Only used if DoubleQuote==NoDoubleQuote.
// Defaults to DefaultEscapeChar.
EscapeChar rune
// Character to use as quotation mark around quoted fields. Defaults to
// DefaultQuoteChar.
QuoteChar rune
// String that separates each record in a CSV file. Defaults to
// DefaultLineTerminator.
LineTerminator string
// Comment, if not 0, is the comment character. Lines beginning with the
// Comment character without preceding whitespace are ignored.
// With leading whitespace the Comment character becomes part of the
// field, even if TrimLeadingSpace is true.
// Comment must be a valid rune and must not be \r, \n,
// or the Unicode replacement character (0xFFFD).
// It must also not be equal to Comma.
Comment rune
}
A Dialect specifies the format of a CSV file. This structure is used by a Reader or Writer to know how to operate on the file they are reading/writing.
type DoubleQuoteMode ¶
type DoubleQuoteMode int
DoubleQuoteMode defined how quote excaping should be done.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader reads records from a CSV-encoded file.
Can be created by calling either NewReader or using NewDialectReader.
func NewDialectReader ¶
Create a custom CSV reader.
func NewReader ¶
Creates a reader that conforms to RFC 4180 and behaves identical as a encoding/csv.Reader.
See `Default*` constants for default dialect used.
func (*Reader) Read ¶
Read reads one record from r. The record is a slice of strings with each string representing one field.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer writes records to a CSV encoded file.
Can be created by calling either NewWriter or using NewDialectWriter.
func NewDialectWriter ¶
Create a custom CSV writer.
func NewWriter ¶
Create a writer that conforms to RFC 4180 and behaves identical as a encoding/csv.Reader.
See `Default*` constants for default dialect used.
func (Writer) Flush ¶
func (w Writer) Flush()
Flush writes any buffered data to the underlying io.Writer. To check if an error occurred during the Flush, call Error.
Directories
¶
| Path | Synopsis |
|---|---|
|
Helpers that makes it easy to build CSV dialects.
|
Helpers that makes it easy to build CSV dialects. |
|
Interfaces shared among go-csv and the Go standard library's encoding/csv.
|
Interfaces shared among go-csv and the Go standard library's encoding/csv. |