-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtypes.go
More file actions
58 lines (49 loc) · 1.48 KB
/
Copy pathtypes.go
File metadata and controls
58 lines (49 loc) · 1.48 KB
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
53
54
55
56
57
58
package gotoon
// EncodeOptions represents the options for encoding values to TOON format
type EncodeOptions struct {
// Indent is the number of spaces per indentation level (default: 2)
Indent int
// Delimiter is the delimiter to use for array values and tabular rows
// Valid values: "," (comma), "\t" (tab), "|" (pipe)
// Default: ","
Delimiter string
// LengthMarker when true adds "#" prefix to array lengths (e.g., [#3] instead of [3])
// Default: false
LengthMarker bool
}
// EncodeOption is a function that modifies EncodeOptions
type EncodeOption func(*EncodeOptions)
// WithIndent sets the number of spaces per indentation level
func WithIndent(n int) EncodeOption {
return func(opts *EncodeOptions) {
opts.Indent = n
}
}
// WithDelimiter sets the delimiter for array values and tabular rows
func WithDelimiter(d string) EncodeOption {
return func(opts *EncodeOptions) {
opts.Delimiter = d
}
}
// WithLengthMarker enables the length marker prefix for arrays
func WithLengthMarker() EncodeOption {
return func(opts *EncodeOptions) {
opts.LengthMarker = true
}
}
// defaultOptions returns the default encoding options
func defaultOptions() *EncodeOptions {
return &EncodeOptions{
Indent: 2,
Delimiter: DefaultDelimiter,
LengthMarker: false,
}
}
// resolveOptions applies the given options to the default options
func resolveOptions(opts []EncodeOption) *EncodeOptions {
options := defaultOptions()
for _, opt := range opts {
opt(options)
}
return options
}