Repository navigation
Expand file tree
/
Copy pathformatter.go
More file actions
137 lines (131 loc) · 3.26 KB
/
Copy pathformatter.go
File metadata and controls
137 lines (131 loc) · 3.26 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package messageformat
import (
"fmt"
"strconv"
"github.com/iawaknahc/gomessageformat/icu4c"
)
func formatValue(value interface{}) (out string, err error) {
switch v := value.(type) {
case int8:
out = strconv.FormatInt(int64(v), 10)
case int16:
out = strconv.FormatInt(int64(v), 10)
case int32:
out = strconv.FormatInt(int64(v), 10)
case int64:
out = strconv.FormatInt(v, 10)
case int:
out = strconv.FormatInt(int64(v), 10)
case uint8:
out = strconv.FormatUint(uint64(v), 10)
case uint16:
out = strconv.FormatUint(uint64(v), 10)
case uint32:
out = strconv.FormatUint(uint64(v), 10)
case uint64:
out = strconv.FormatUint(v, 10)
case uint:
out = strconv.FormatUint(uint64(v), 10)
case float32:
out = strconv.FormatFloat(float64(v), 'f', -1, 32)
case float64:
out = strconv.FormatFloat(v, 'f', -1, 64)
case string:
out = v
case bool:
out = strconv.FormatBool(v)
default:
err = fmt.Errorf("unsupported argument type: %T", value)
}
return
}
func offsetValue(value interface{}, offset int) (out interface{}, err error) {
switch v := value.(type) {
case int8:
out = int8(int64(v) - int64(offset))
case int16:
out = int16(int64(v) - int64(offset))
case int32:
out = int32(int64(v) - int64(offset))
case int64:
out = int64(int64(v) - int64(offset))
case int:
out = int(int64(v) - int64(offset))
case uint8:
out = uint8(int64(v) - int64(offset))
case uint16:
out = uint16(int64(v) - int64(offset))
case uint32:
out = uint32(int64(v) - int64(offset))
case uint64:
out = uint64(int64(v) - int64(offset))
case uint:
out = uint(int64(v) - int64(offset))
case float32:
out = float32(float32(v) - float32(offset))
case float64:
out = float64(float64(v) - float64(offset))
case string:
var f64 float64
f64, err = strconv.ParseFloat(v, 64)
if err != nil {
return
}
out = strconv.FormatFloat(f64-float64(offset), 'f', -1, 64)
default:
err = fmt.Errorf("expected numeric type: %T", value)
}
return
}
func matchExplicitValue(value interface{}, explicitValue int) (match bool, err error) {
switch v := value.(type) {
case int8:
match = int64(v) == int64(explicitValue)
case int16:
match = int64(v) == int64(explicitValue)
case int32:
match = int64(v) == int64(explicitValue)
case int64:
match = int64(v) == int64(explicitValue)
case int:
match = v == explicitValue
case uint8:
match = int64(v) == int64(explicitValue)
case uint16:
match = int64(v) == int64(explicitValue)
case uint32:
match = int64(v) == int64(explicitValue)
case uint64:
match = int64(v) == int64(explicitValue)
case uint:
match = int64(v) == int64(explicitValue)
case float32:
match = float32(v) == float32(explicitValue)
case float64:
match = float64(v) == float64(explicitValue)
case string:
var f64 float64
f64, err = strconv.ParseFloat(v, 64)
if err != nil {
return
}
match = f64 == float64(explicitValue)
default:
err = fmt.Errorf("expected numeric type: %T", value)
}
return
}
func styleToStyle(style string) icu4c.DateFormatStyle {
switch style {
case "short":
return icu4c.DateFormatStyleShort
case "medium":
return icu4c.DateFormatStyleMedium
case "long":
return icu4c.DateFormatStyleLong
case "full":
return icu4c.DateFormatStyleFull
default:
panic(fmt.Errorf("unexpected style: %v", style))
}
}