forked from LindsayBradford/go-dbf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolumntype.go
61 lines (54 loc) · 1.14 KB
/
columntype.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
package dbf
import "fmt"
// ColumnType is the data type of the dbf column
type ColumnType rune
func (c ColumnType) String() string {
switch c {
case TypeText:
return "Text"
case TypeBool:
return "Bool"
case TypeDate:
return "Date"
case TypeNumber:
return "Number"
case TypeFloat:
return "Float"
case TypeMemo:
return "Memo"
default:
return "unknown: " + string(c)
}
}
var (
// TypeText is a string field
TypeText ColumnType = 'C'
// TypeBool is a boolean field
TypeBool ColumnType = 'L'
// TypeDate is a date field
TypeDate ColumnType = 'D'
// TypeNumber is an integer number
TypeNumber ColumnType = 'N'
// TypeFloat is a float number
TypeFloat ColumnType = 'F'
// TypeMemo is a memo
TypeMemo ColumnType = 'M'
// TypeUnknown is used when the type is not known
TypeUnknown ColumnType = '?'
)
func getColumnType(r byte) (ColumnType, error) {
allowedTypes := []ColumnType{
TypeText,
TypeBool,
TypeDate,
TypeNumber,
TypeFloat,
TypeMemo,
}
for _, t := range allowedTypes {
if t == ColumnType(r) {
return ColumnType(r), nil
}
}
return TypeUnknown, fmt.Errorf("column / field type %c is not supported", r)
}