File tree 1 file changed +10
-33
lines changed
1 file changed +10
-33
lines changed Original file line number Diff line number Diff line change @@ -32,48 +32,25 @@ func ordinal(i int) string {
32
32
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#format
33
33
func parseFormatFuncSpecifiers (f string , n int ) map [int ]struct {} {
34
34
ret := make (map [int ]struct {}, n )
35
-
36
- type state int
37
- const (
38
- init state = iota // Initial state
39
- brace // {
40
- digit // 0..9
41
- )
42
-
43
- var cur state
44
- var start int
35
+ start := - 1
45
36
for i , r := range f {
46
- switch cur {
47
- case init :
48
- switch r {
49
- case '{' :
50
- cur = brace
37
+ if r == '{' {
38
+ if start == i {
39
+ start = - 1 // When the '{' is escaped like '{{'
40
+ } else {
51
41
start = i + 1 // `+ 1` because `i` points char '{'
52
42
}
53
- case brace :
54
- switch {
55
- case '0' <= r && r <= '9' :
56
- cur = digit
57
- default :
58
- cur = init
43
+ } else if start >= 0 {
44
+ if '0' <= r && r <= '9' {
45
+ continue
59
46
}
60
- case digit :
61
- switch {
62
- case '0' <= r && r <= '9' :
63
- // Do nothing
64
- case r == '{' :
65
- cur = brace
66
- start = i + 1
67
- case r == '}' :
47
+ if r == '}' && start < i {
68
48
i , _ := strconv .Atoi (f [start :i ])
69
49
ret [i ] = struct {}{}
70
- cur = init
71
- default :
72
- cur = init
73
50
}
51
+ start = - 1 // Done
74
52
}
75
53
}
76
-
77
54
return ret
78
55
}
79
56
You can’t perform that action at this time.
0 commit comments