File tree 1 file changed +10
-36
lines changed
1 file changed +10
-36
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,10 @@ package actionlint
2
2
3
3
import (
4
4
"fmt"
5
- "regexp"
6
5
"strconv"
7
6
"strings"
8
7
)
9
8
10
- var reFormatPlaceholder = regexp .MustCompile (`{\d+}` )
11
-
12
9
func ordinal (i int ) string {
13
10
suffix := "th"
14
11
switch i % 10 {
@@ -32,48 +29,25 @@ func ordinal(i int) string {
32
29
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#format
33
30
func parseFormatFuncSpecifiers (f string , n int ) map [int ]struct {} {
34
31
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
32
+ start := - 1
45
33
for i , r := range f {
46
- switch cur {
47
- case init :
48
- switch r {
49
- case '{' :
50
- cur = brace
34
+ if r == '{' {
35
+ if start == i {
36
+ start = - 1 // When the '{' is escaped like '{{'
37
+ } else {
51
38
start = i + 1 // `+ 1` because `i` points char '{'
52
39
}
53
- case brace :
54
- switch {
55
- case '0' <= r && r <= '9' :
56
- cur = digit
57
- default :
58
- cur = init
40
+ } else if start >= 0 {
41
+ if '0' <= r && r <= '9' {
42
+ continue
59
43
}
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 == '}' :
44
+ if r == '}' && start < i {
68
45
i , _ := strconv .Atoi (f [start :i ])
69
46
ret [i ] = struct {}{}
70
- cur = init
71
- default :
72
- cur = init
73
47
}
48
+ start = - 1 // Done
74
49
}
75
50
}
76
-
77
51
return ret
78
52
}
79
53
You can’t perform that action at this time.
0 commit comments