1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

build: use sequence Split introduced in go1.24

This commit is contained in:
Nick Craig-Wood
2025-09-14 16:16:26 +01:00
parent 4368863fcb
commit 71b9b4ad7a
20 changed files with 28 additions and 28 deletions

View File

@@ -684,7 +684,7 @@ func (f *Fs) rcFetch(ctx context.Context, in rc.Params) (rc.Params, error) {
start, end int64 start, end int64
} }
parseChunks := func(ranges string) (crs []chunkRange, err error) { parseChunks := func(ranges string) (crs []chunkRange, err error) {
for _, part := range strings.Split(ranges, ",") { for part := range strings.SplitSeq(ranges, ",") {
var start, end int64 = 0, math.MaxInt64 var start, end int64 = 0, math.MaxInt64
switch ints := strings.Split(part, ":"); len(ints) { switch ints := strings.Split(part, ":"); len(ints) {
case 1: case 1:

View File

@@ -18,7 +18,7 @@ type headerLink struct {
} }
func parseLinkHeader(header string) (links []headerLink) { func parseLinkHeader(header string) (links []headerLink) {
for _, link := range strings.Split(header, ",") { for link := range strings.SplitSeq(header, ",") {
link = strings.TrimSpace(link) link = strings.TrimSpace(link)
parsed := parseLink(link) parsed := parseLink(link)
if parsed != nil { if parsed != nil {
@@ -30,7 +30,7 @@ func parseLinkHeader(header string) (links []headerLink) {
func parseLink(link string) (parsedLink *headerLink) { func parseLink(link string) (parsedLink *headerLink) {
var parts []string var parts []string
for _, part := range strings.Split(link, ";") { for part := range strings.SplitSeq(link, ";") {
parts = append(parts, strings.TrimSpace(part)) parts = append(parts, strings.TrimSpace(part))
} }

View File

@@ -191,7 +191,7 @@ func driveScopes(scopesString string) (scopes []string) {
if scopesString == "" { if scopesString == "" {
scopesString = defaultScope scopesString = defaultScope
} }
for _, scope := range strings.Split(scopesString, ",") { for scope := range strings.SplitSeq(scopesString, ",") {
scope = strings.TrimSpace(scope) scope = strings.TrimSpace(scope)
scopes = append(scopes, scopePrefix+scope) scopes = append(scopes, scopePrefix+scope)
} }
@@ -1220,7 +1220,7 @@ func isLinkMimeType(mimeType string) bool {
// into a list of unique extensions with leading "." and a list of associated MIME types // into a list of unique extensions with leading "." and a list of associated MIME types
func parseExtensions(extensionsIn ...string) (extensions, mimeTypes []string, err error) { func parseExtensions(extensionsIn ...string) (extensions, mimeTypes []string, err error) {
for _, extensionText := range extensionsIn { for _, extensionText := range extensionsIn {
for _, extension := range strings.Split(extensionText, ",") { for extension := range strings.SplitSeq(extensionText, ",") {
extension = strings.ToLower(strings.TrimSpace(extension)) extension = strings.ToLower(strings.TrimSpace(extension))
if extension == "" { if extension == "" {
continue continue

View File

@@ -400,7 +400,7 @@ type quirks struct {
} }
func (q *quirks) parseQuirks(option string) { func (q *quirks) parseQuirks(option string) {
for _, flag := range strings.Split(option, ",") { for flag := range strings.SplitSeq(option, ",") {
switch strings.ToLower(strings.TrimSpace(flag)) { switch strings.ToLower(strings.TrimSpace(flag)) {
case "binlist": case "binlist":
// The official client sometimes uses a so called "bin" protocol, // The official client sometimes uses a so called "bin" protocol,
@@ -1770,7 +1770,7 @@ func (f *Fs) parseSpeedupPatterns(patternString string) (err error) {
f.speedupAny = false f.speedupAny = false
uniqueValidPatterns := make(map[string]any) uniqueValidPatterns := make(map[string]any)
for _, pattern := range strings.Split(patternString, ",") { for pattern := range strings.SplitSeq(patternString, ",") {
pattern = strings.ToLower(strings.TrimSpace(pattern)) pattern = strings.ToLower(strings.TrimSpace(pattern))
if pattern == "" { if pattern == "" {
continue continue

View File

@@ -123,7 +123,7 @@ func (p *Prop) Hashes() (hashes map[hash.Type]string) {
hashes = make(map[hash.Type]string) hashes = make(map[hash.Type]string)
for _, checksums := range p.Checksums { for _, checksums := range p.Checksums {
checksums = strings.ToLower(checksums) checksums = strings.ToLower(checksums)
for _, checksum := range strings.Split(checksums, " ") { for checksum := range strings.SplitSeq(checksums, " ") {
switch { switch {
case strings.HasPrefix(checksum, "sha1:"): case strings.HasPrefix(checksum, "sha1:"):
hashes[hash.SHA1] = checksum[5:] hashes[hash.SHA1] = checksum[5:]

View File

@@ -33,7 +33,7 @@ func readCommits(from, to string) (logMap map[string]string, logs []string) {
} }
logMap = map[string]string{} logMap = map[string]string{}
logs = []string{} logs = []string{}
for _, line := range bytes.Split(out, []byte{'\n'}) { for line := range bytes.SplitSeq(out, []byte{'\n'}) {
if len(line) == 0 { if len(line) == 0 {
continue continue
} }

View File

@@ -522,7 +522,7 @@ func (b *bisyncTest) runTestCase(ctx context.Context, t *testing.T, testCase str
require.NoError(b.t, err) require.NoError(b.t, err)
b.step = 0 b.step = 0
b.stopped = false b.stopped = false
for _, line := range strings.Split(string(scenBuf), "\n") { for line := range strings.SplitSeq(string(scenBuf), "\n") {
comment := strings.Index(line, "#") comment := strings.Index(line, "#")
if comment != -1 { if comment != -1 {
line = line[:comment] line = line[:comment]
@@ -936,7 +936,7 @@ func (b *bisyncTest) runTestStep(ctx context.Context, line string) (err error) {
// splitLine splits scenario line into tokens and performs // splitLine splits scenario line into tokens and performs
// substitutions that involve whitespace or control chars. // substitutions that involve whitespace or control chars.
func splitLine(line string) (args []string) { func splitLine(line string) (args []string) {
for _, s := range strings.Fields(line) { for s := range strings.FieldsSeq(line) {
b := []byte(whitespaceReplacer.Replace(s)) b := []byte(whitespaceReplacer.Replace(s))
b = regexChar.ReplaceAllFunc(b, func(b []byte) []byte { b = regexChar.ReplaceAllFunc(b, func(b []byte) []byte {
c, _ := strconv.ParseUint(string(b[5:7]), 16, 8) c, _ := strconv.ParseUint(string(b[5:7]), 16, 8)
@@ -1513,7 +1513,7 @@ func (b *bisyncTest) compareResults() int {
fs.Log(nil, divider) fs.Log(nil, divider)
fs.Logf(nil, color(terminal.RedFg, "| MISCOMPARE -Golden vs +Results for %s"), file) fs.Logf(nil, color(terminal.RedFg, "| MISCOMPARE -Golden vs +Results for %s"), file)
for _, line := range strings.Split(strings.TrimSpace(text), "\n") { for line := range strings.SplitSeq(strings.TrimSpace(text), "\n") {
fs.Logf(nil, "| %s", strings.TrimSpace(line)) fs.Logf(nil, "| %s", strings.TrimSpace(line))
} }
} }

View File

@@ -219,8 +219,8 @@ func (b *bisyncRun) setFromCompareFlag(ctx context.Context) error {
return nil return nil
} }
var CompareFlag CompareOpt // for exclusions var CompareFlag CompareOpt // for exclusions
opts := strings.Split(b.opt.CompareFlag, ",") opts := strings.SplitSeq(b.opt.CompareFlag, ",")
for _, opt := range opts { for opt := range opts {
switch strings.ToLower(strings.TrimSpace(opt)) { switch strings.ToLower(strings.TrimSpace(opt)) {
case "size": case "size":
b.opt.Compare.Size = true b.opt.Compare.Size = true

View File

@@ -344,7 +344,7 @@ func showBackend(name string) {
} }
for _, ex := range opt.Examples { for _, ex := range opt.Examples {
fmt.Printf(" - %s\n", quoteString(ex.Value)) fmt.Printf(" - %s\n", quoteString(ex.Value))
for _, line := range strings.Split(ex.Help, "\n") { for line := range strings.SplitSeq(ex.Help, "\n") {
fmt.Printf(" - %s\n", line) fmt.Printf(" - %s\n", line)
} }
} }

View File

@@ -182,7 +182,7 @@ func (p *Proxy) run(in map[string]string) (config configmap.Simple, err error) {
// Obscure any values in the config map that need it // Obscure any values in the config map that need it
obscureFields, ok := config.Get("_obscure") obscureFields, ok := config.Get("_obscure")
if ok { if ok {
for _, key := range strings.Split(obscureFields, ",") { for key := range strings.SplitSeq(obscureFields, ",") {
value, ok := config.Get(key) value, ok := config.Get(key)
if ok { if ok {
obscuredValue, err := obscure.Obscure(value) obscuredValue, err := obscure.Obscure(value)

View File

@@ -95,7 +95,7 @@ func (e *Position) UnmarshalText(text []byte) error {
switch s := strings.ToLower(string(text)); s { switch s := strings.ToLower(string(text)); s {
default: default:
*e = PositionNone *e = PositionNone
for _, p := range strings.Split(s, ",") { for p := range strings.SplitSeq(s, ",") {
switch p { switch p {
case "left": case "left":
*e |= PositionLeft *e |= PositionLeft

View File

@@ -351,7 +351,7 @@ func TestEnvironmentVariables(t *testing.T) {
parseFileFilters := func(out string) (extensions []string) { parseFileFilters := func(out string) (extensions []string) {
// Match: - (^|/)[^/]*\.jpg$ // Match: - (^|/)[^/]*\.jpg$
find := regexp.MustCompile(`^- \(\^\|\/\)\[\^\/\]\*\\\.(.*?)\$$`) find := regexp.MustCompile(`^- \(\^\|\/\)\[\^\/\]\*\\\.(.*?)\$$`)
for _, line := range strings.Split(out, "\n") { for line := range strings.SplitSeq(out, "\n") {
if m := find.FindStringSubmatch(line); m != nil { if m := find.FindStringSubmatch(line); m != nil {
extensions = append(extensions, m[1]) extensions = append(extensions, m[1])
} }

View File

@@ -70,7 +70,7 @@ func (gs *Groups) Include(groupsString string) *Groups {
return gs return gs
} }
want := map[string]bool{} want := map[string]bool{}
for _, groupName := range strings.Split(groupsString, ",") { for groupName := range strings.SplitSeq(groupsString, ",") {
_, ok := All.ByName[groupName] _, ok := All.ByName[groupName]
if !ok { if !ok {
fs.Fatalf(nil, "Couldn't find group %q in command annotation", groupName) fs.Fatalf(nil, "Couldn't find group %q in command annotation", groupName)
@@ -173,7 +173,7 @@ func installFlag(flags *pflag.FlagSet, name string, groupsString string) {
// Add flag to Group if it is a global flag // Add flag to Group if it is a global flag
if groupsString != "" && flags == pflag.CommandLine { if groupsString != "" && flags == pflag.CommandLine {
for _, groupName := range strings.Split(groupsString, ",") { for groupName := range strings.SplitSeq(groupsString, ",") {
if groupName == "rc-" { if groupName == "rc-" {
groupName = "RC" groupName = "RC"
} }

View File

@@ -32,7 +32,7 @@ func init() {
{"video/x-matroska", ".mpv,.mkv"}, {"video/x-matroska", ".mpv,.mkv"},
{"application/x-subrip", ".srt"}, {"application/x-subrip", ".srt"},
} { } {
for _, ext := range strings.Split(t.extensions, ",") { for ext := range strings.SplitSeq(t.extensions, ",") {
if mime.TypeByExtension(ext) == "" { if mime.TypeByExtension(ext) == "" {
err := mime.AddExtensionType(ext, t.mimeType) err := mime.AddExtensionType(ext, t.mimeType)
if err != nil { if err != nil {

View File

@@ -64,7 +64,7 @@ func filterBlocks(in Params, f func(oi fs.OptionsInfo)) (err error) {
return err return err
} }
blocks := map[string]struct{}{} blocks := map[string]struct{}{}
for _, name := range strings.Split(blocksStr, ",") { for name := range strings.SplitSeq(blocksStr, ",") {
if name != "" { if name != "" {
blocks[name] = struct{}{} blocks[name] = struct{}{}
} }

View File

@@ -743,7 +743,7 @@ func parseTrackRenamesStrategy(strategies string) (strategy trackRenamesStrategy
if len(strategies) == 0 { if len(strategies) == 0 {
return strategy, nil return strategy, nil
} }
for _, s := range strings.Split(strategies, ",") { for s := range strings.SplitSeq(strategies, ",") {
switch s { switch s {
case "hash": case "hash":
strategy |= trackRenamesStrategyHash strategy |= trackRenamesStrategyHash

View File

@@ -157,7 +157,7 @@ func testsToRegexp(tests []string) string {
// Make a trie showing which parts are used at each level // Make a trie showing which parts are used at each level
for _, test := range tests { for _, test := range tests {
parent := split parent := split
for _, name := range strings.Split(test, "/") { for name := range strings.SplitSeq(test, "/") {
current := parent[name] current := parent[name]
if current == nil { if current == nil {
current = trie{} current = trie{}

View File

@@ -82,7 +82,7 @@ func start(name string) error {
// parse the output and set environment vars from it // parse the output and set environment vars from it
var connect string var connect string
var connectDelay time.Duration var connectDelay time.Duration
for _, line := range bytes.Split(out, []byte("\n")) { for line := range bytes.SplitSeq(out, []byte("\n")) {
line = bytes.TrimSpace(line) line = bytes.TrimSpace(line)
part := matchLine.FindSubmatch(line) part := matchLine.FindSubmatch(line)
if part != nil { if part != nil {

View File

@@ -184,8 +184,8 @@ func (mask MultiEncoder) String() string {
// Set converts a string into a MultiEncoder // Set converts a string into a MultiEncoder
func (mask *MultiEncoder) Set(in string) error { func (mask *MultiEncoder) Set(in string) error {
var out MultiEncoder var out MultiEncoder
parts := strings.Split(in, ",") parts := strings.SplitSeq(in, ",")
for _, part := range parts { for part := range parts {
part = strings.TrimSpace(part) part = strings.TrimSpace(part)
if bits, ok := nameToEncoding[part]; ok { if bits, ok := nameToEncoding[part]; ok {
out |= bits out |= bits

View File

@@ -212,7 +212,7 @@ type dirMap map[string]struct{}
// Create a dirMap from a string // Create a dirMap from a string
func newDirMap(dirString string) (dm dirMap) { func newDirMap(dirString string) (dm dirMap) {
dm = make(dirMap) dm = make(dirMap)
for _, entry := range strings.Split(dirString, "|") { for entry := range strings.SplitSeq(dirString, "|") {
if entry != "" { if entry != "" {
dm[entry] = struct{}{} dm[entry] = struct{}{}
} }