Skip to content

Commit 40adb81

Browse files
committed
Restore Go 1.18 compatibility
1 parent ca271b9 commit 40adb81

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

adif/cabrillo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (o *CabrilloIO) Write(l *Logfile, out io.Writer) error {
159159
}
160160
headers := make(map[string]string)
161161
for _, f := range l.Header.Fields() {
162-
if h, ok := strings.CutPrefix(f.Name, "APP_CABRILLO_"); ok {
162+
if h, ok := cutPrefix(f.Name, "APP_CABRILLO_"); ok {
163163
headers[strings.Replace(h, "_", "-", -1)] = f.Value
164164
}
165165
}

adif/util.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package adif
1616

1717
import (
18+
"fmt"
1819
"strings"
1920
)
2021

@@ -74,5 +75,26 @@ func fieldValues(l *Logfile, fname string) map[string]int {
7475
}
7576

7677
func isAllDigits(s string) bool {
77-
return !strings.ContainsFunc(s, func(r rune) bool { return r < '0' || r > '9' })
78+
// TODO when upgrading to Go 1.20+, use
79+
// return !strings.ContainsFunc(s, func(r rune) bool { return r < '0' || r > '9' })
80+
for _, r := range s {
81+
if r < '0' || r > '9' {
82+
return false
83+
}
84+
}
85+
return true
86+
}
87+
88+
// cutPrefix is a polyfill for strings.CutPrefix which was introduced in Go 1.20.
89+
func cutPrefix(s, prefix string) (after string, found bool) {
90+
// TODO when upgrading to Go 1.20+ remove this polyfill
91+
if strings.HasPrefix(s, prefix) {
92+
var before string
93+
before, after, found = strings.Cut(s, prefix)
94+
if !found || before != "" {
95+
panic(fmt.Sprintf("strings.Cut(%q, %q) got %q, %q, %v", s, prefix, before, after, found))
96+
}
97+
return
98+
}
99+
return s, false
78100
}

0 commit comments

Comments
 (0)