-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypes.go
113 lines (98 loc) · 1.72 KB
/
types.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package text
import (
"errors"
"fmt"
"reflect"
"strings"
)
type Encoding uint8
const (
AUTO Encoding = iota
UTF8
UTF8M
UTF16
UTF16BEM
UTF16LEM
UTF16BE
UTF16LE
SJIS
)
var EncodingLiteral = map[Encoding]string{
AUTO: "AUTO",
UTF8: "UTF8",
UTF8M: "UTF8M",
UTF16: "UTF16",
UTF16BEM: "UTF16BEM",
UTF16LEM: "UTF16LEM",
UTF16BE: "UTF16BE",
UTF16LE: "UTF16LE",
SJIS: "SJIS",
}
func (e Encoding) String() string {
return EncodingLiteral[e]
}
type LineBreak string
const (
CR LineBreak = "\r"
LF LineBreak = "\n"
CRLF LineBreak = "\r\n"
)
var LineBreakLiteral = map[LineBreak]string{
CR: "CR",
LF: "LF",
CRLF: "CRLF",
}
func (lb LineBreak) Value() string {
return reflect.ValueOf(lb).String()
}
func (lb LineBreak) String() string {
return LineBreakLiteral[lb]
}
type FieldAlignment int
const (
NotAligned FieldAlignment = iota
Centering
RightAligned
LeftAligned
)
type RawText []byte
func ParseEncoding(s string) (Encoding, error) {
var encoding Encoding
switch strings.ToUpper(s) {
case "AUTO":
encoding = AUTO
case "UTF8":
encoding = UTF8
case "UTF8M":
encoding = UTF8M
case "UTF16":
encoding = UTF16
case "UTF16BEM":
encoding = UTF16BEM
case "UTF16LEM":
encoding = UTF16LEM
case "UTF16BE":
encoding = UTF16BE
case "UTF16LE":
encoding = UTF16LE
case "SJIS":
encoding = SJIS
default:
return encoding, errors.New(fmt.Sprintf("%q cannot convert to Encoding", s))
}
return encoding, nil
}
func ParseLineBreak(s string) (LineBreak, error) {
var lb LineBreak
switch strings.ToUpper(s) {
case "CRLF":
lb = CRLF
case "CR":
lb = CR
case "LF":
lb = LF
default:
return lb, errors.New(fmt.Sprintf("%q cannot convert to LineBreak", s))
}
return lb, nil
}