@@ -11,12 +11,12 @@ import (
11
11
"os"
12
12
"os/exec"
13
13
"path/filepath"
14
+ "regexp"
14
15
"runtime"
15
16
"sort"
16
17
"strings"
17
18
"text/template"
18
19
"time"
19
- "unicode"
20
20
21
21
"github.com/magefile/mage/internal"
22
22
"github.com/magefile/mage/mg"
@@ -30,13 +30,28 @@ import (
30
30
// change the inputs to the compiling process.
31
31
const magicRebuildKey = "v0.3"
32
32
33
+ // (Aaaa)(Bbbb) -> aaaaBbbb
34
+ var firstWordRx = regexp .MustCompile (`^([[:upper:]][^[:upper:]]+)([[:upper:]].*)$` )
35
+
36
+ // (AAAA)(Bbbb) -> aaaaBbbb
37
+ var firstAbbrevRx = regexp .MustCompile (`^([[:upper:]]+)([[:upper:]][^[:upper:]].*)$` )
38
+
39
+ func lowerFirstWord (s string ) string {
40
+ if match := firstWordRx .FindStringSubmatch (s ); match != nil {
41
+ return strings .ToLower (match [1 ]) + match [2 ]
42
+ }
43
+ if match := firstAbbrevRx .FindStringSubmatch (s ); match != nil {
44
+ return strings .ToLower (match [1 ]) + match [2 ]
45
+ }
46
+ return strings .ToLower (s )
47
+ }
48
+
33
49
var mainfileTemplate = template .Must (template .New ("" ).Funcs (map [string ]interface {}{
34
50
"lower" : strings .ToLower ,
35
51
"lowerFirst" : func (s string ) string {
36
52
parts := strings .Split (s , ":" )
37
53
for i , t := range parts {
38
- r := []rune (t )
39
- parts [i ] = string (unicode .ToLower (r [0 ])) + string (r [1 :])
54
+ parts [i ] = lowerFirstWord (t )
40
55
}
41
56
return strings .Join (parts , ":" )
42
57
},
0 commit comments