-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.go
52 lines (45 loc) · 1.28 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package csvutil
/*
* Filename: config.go
* Package: csvutil
* Author: Bryan Matsuo <[email protected]>
* Created: Tue Jul 12 01:56:03 PDT 2011
* Description: Define the configuration type for Readers and Writers.
*/
import ()
// A configuration structure that can be shared between a Reader and Writer.
type Config struct {
// General configuration
// Field seperator
Sep rune
// Trim leading/trailing whitespace in fields.
Trim bool
// Characters to trim from fields.
Cutset string
// Prefix for comment lines.
CommentPrefix string
// Reader specific config
// Are comments allowed in the input.
Comments bool
// Comments can appear in the body (Comments must be true).
CommentsInBody bool
}
// The default configuration is used for Readers and Writers when none is
// given.
var (
DefaultConfig = &Config{
Sep: ',', Trim: false, Cutset: " \t", CommentPrefix: "#",
Comments: false, CommentsInBody: false}
)
// Return a freshly allocated Config that is initialized to DefaultConfig.
func NewConfig() *Config {
var c = new(Config)
*c = *DefaultConfig
return c
}
func (c *Config) LooksLikeComment(line string) bool {
return line[:len(c.CommentPrefix)] == c.CommentPrefix
}
func (c *Config) IsSep(rune rune) bool {
return rune == c.Sep
}