-
Notifications
You must be signed in to change notification settings - Fork 5
/
format.go
72 lines (63 loc) · 1.86 KB
/
format.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package px
import (
"io"
"regexp"
)
type (
FormatMap OrderedMap
Format interface {
Value
HasStringFlags() bool
ApplyStringFlags(b io.Writer, str string, quoted bool)
Width() int
Precision() int
FormatChar() byte
Plus() byte
IsAlt() bool
IsLeft() bool
IsZeroPad() bool
LeftDelimiter() byte
ContainerFormats() FormatMap
Separator(dflt string) string
Separator2(dflt string) string
OrigFormat() string
ReplaceFormatChar(c byte) Format
WithoutWidth() Format
}
Indentation interface {
Breaks() bool
Increase(indenting bool) Indentation
IsFirst() bool
IsIndenting() bool
Indenting(indenting bool) Indentation
Level() int
Padding() string
Subsequent() Indentation
}
FormatContext interface {
Indentation() Indentation
FormatMap() FormatMap
Property(key string) (string, bool)
Properties() map[string]string
SetProperty(key, value string)
Subsequent() FormatContext
UnsupportedFormat(t Type, supportedFormats string, actualFormat Format) error
WithProperties(properties map[string]string) FormatContext
}
)
var FormatPattern = regexp.MustCompile(`\A%([\s\[+#0{<(|-]*)([1-9][0-9]*)?(?:\.([0-9]+))?([a-zA-Z])\z`)
var DefaultFormat Format
var DefaultFormatContext FormatContext
var Pretty FormatContext
var PrettyExpanded FormatContext
var NewFormat func(format string) Format
var NewIndentation func(indenting bool, level int) Indentation
var NewFormatContext func(t Type, format Format, indentation Indentation) FormatContext
var NewFormatContext2 func(indentation Indentation, formatMap FormatMap, properties map[string]string) FormatContext
var NewFormatContext3 func(value Value, format Value) (FormatContext, error)
func GetFormat(f FormatMap, t Type) Format {
if v, ok := f.Find(func(ev Value) bool { return IsAssignable(ev.(MapEntry).Key().(Type), t) }); ok {
return v.(MapEntry).Value().(Format)
}
return DefaultFormat
}