diff options
| author | Shulhan <ms@kilabit.info> | 2025-01-23 03:40:50 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-01-23 03:41:10 +0700 |
| commit | 2a0694d2fa577574b505c4635eb8a824eaf88ddc (patch) | |
| tree | cce840739c7f59893c3a6a65a1600f9f857c484e /lib/ini | |
| parent | 605d847b236dde031a2e387e74298d66a27b5e0a (diff) | |
| download | pakakeh.go-2a0694d2fa577574b505c4635eb8a824eaf88ddc.tar.xz | |
all: use for-range with numeric
Go 1.22 now support for-range on numeric value.
Diffstat (limited to 'lib/ini')
| -rw-r--r-- | lib/ini/common_test.go | 9 | ||||
| -rw-r--r-- | lib/ini/ini.go | 15 | ||||
| -rw-r--r-- | lib/ini/section.go | 16 | ||||
| -rw-r--r-- | lib/ini/tag_struct_field.go | 8 |
4 files changed, 23 insertions, 25 deletions
diff --git a/lib/ini/common_test.go b/lib/ini/common_test.go index 5ceaa3eb..c41de518 100644 --- a/lib/ini/common_test.go +++ b/lib/ini/common_test.go @@ -1,6 +1,6 @@ -// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2018 M. Shulhan <ms@kilabit.info> +// +// SPDX-License-Identifier: BSD-3-Clause package ini @@ -110,12 +110,11 @@ func TestParseTag_fromStruct(t *testing.T) { field reflect.StructField tag string got []string - x int ) vtype = reflect.TypeOf(adt) - for x = 0; x < vtype.NumField(); x++ { + for x := range vtype.NumField() { field = vtype.Field(x) tag, _, _ = libreflect.Tag(field, "ini") diff --git a/lib/ini/ini.go b/lib/ini/ini.go index 47eeb382..a75ac0d2 100644 --- a/lib/ini/ini.go +++ b/lib/ini/ini.go @@ -155,9 +155,8 @@ func (in *Ini) marshalStruct( tag string layout string tags []string - x int ) - for x = 0; x < numField; x++ { + for x := range numField { field = rtipe.Field(x) fvalue = rvalue.Field(x) ftype = field.Type @@ -396,7 +395,7 @@ func (in *Ini) Section(secName, subName string) (sec *Section) { } secName = strings.ToLower(secName) - for x := 0; x < len(in.secs); x++ { + for x := range len(in.secs) { if secName != in.secs[x].nameLower { continue } @@ -501,7 +500,7 @@ func (in *Ini) addSection(sec *Section) { func (in *Ini) AsMap(sectionName, subName string) (out map[string][]string) { out = make(map[string][]string) - for x := 0; x < len(in.secs); x++ { + for x := range len(in.secs) { sec := in.secs[x] if len(sectionName) > 0 && sectionName != sec.nameLower { @@ -511,7 +510,7 @@ func (in *Ini) AsMap(sectionName, subName string) (out map[string][]string) { continue } - for y := 0; y < len(sec.vars); y++ { + for y := range len(sec.vars) { v := sec.vars[y] if v.mode == lineModeEmpty { @@ -667,7 +666,7 @@ func (in *Ini) Prune() { // mergeSection merge a section (and subsection) into slice. func mergeSection(secs []*Section, newSec *Section) []*Section { - for x := 0; x < len(secs); x++ { + for x := range len(secs) { if secs[x].nameLower != newSec.nameLower { continue } @@ -720,7 +719,7 @@ func (in *Ini) Subs(secName string) (subs []*Section) { secName = strings.ToLower(secName) - for x := 0; x < len(in.secs); x++ { + for x := range len(in.secs) { if in.secs[x].mode == lineModeEmpty || in.secs[x].mode == lineModeComment { continue } @@ -817,7 +816,7 @@ func (in *Ini) Write(w io.Writer) (err error) { v *variable ) - for x := 0; x < len(in.secs); x++ { + for x := range len(in.secs) { // Add an empty line before section statement. if endWithVar { fmt.Fprintln(w) diff --git a/lib/ini/section.go b/lib/ini/section.go index 70b64a9b..7859f961 100644 --- a/lib/ini/section.go +++ b/lib/ini/section.go @@ -1,6 +1,6 @@ -// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2018 M. Shulhan <ms@kilabit.info> +// +// SPDX-License-Identifier: BSD-3-Clause package ini @@ -108,7 +108,7 @@ func (sec *Section) add(key, value string) bool { keyLower := strings.ToLower(key) idx := -1 - for x := 0; x < len(sec.vars); x++ { + for x := range len(sec.vars) { if !isLineModeVar(sec.vars[x].mode) { continue } @@ -144,7 +144,7 @@ func (sec *Section) add(key, value string) bool { // list. func (sec *Section) addUniqValue(key, value string) { keyLower := strings.ToLower(key) - for x := 0; x < len(sec.vars); x++ { + for x := range len(sec.vars) { if sec.vars[x].keyLower == keyLower { if sec.vars[x].value == value { tmp := sec.vars[x] @@ -244,7 +244,7 @@ func (sec *Section) gets(key string, defs []string) (vals []string, ok bool) { } key = strings.ToLower(key) - for x := 0; x < len(sec.vars); x++ { + for x := range len(sec.vars) { if sec.vars[x].keyLower == key { vals = append(vals, sec.vars[x].value) } @@ -258,7 +258,7 @@ func (sec *Section) gets(key string, defs []string) (vals []string, ok bool) { // merge other Section variables on this section, ignoring empty or comment // mode. func (sec *Section) merge(other *Section) { - for x := 0; x < len(other.vars); x++ { + for x := range len(other.vars) { if !isLineModeVar(other.vars[x].mode) { continue } @@ -346,7 +346,7 @@ func (sec *Section) unsetAll(key string) { vars := make([]*variable, 0, len(sec.vars)) key = strings.ToLower(key) - for x := 0; x < len(sec.vars); x++ { + for x := range len(sec.vars) { if sec.vars[x].keyLower != key { // Ignore the last empty line. if x == len(sec.vars)-1 && diff --git a/lib/ini/tag_struct_field.go b/lib/ini/tag_struct_field.go index 7411569d..672d5c97 100644 --- a/lib/ini/tag_struct_field.go +++ b/lib/ini/tag_struct_field.go @@ -1,6 +1,6 @@ -// Copyright 2021, Shulhan <ms@kilabit.info>. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2021 M. Shulhan <ms@kilabit.info> +// +// SPDX-License-Identifier: BSD-3-Clause package ini @@ -34,7 +34,7 @@ func unpackTagStructField(rtype reflect.Type, rval reflect.Value) (out *tagStruc return out } - for x := 0; x < numField; x++ { + for x := range numField { field := rtype.Field(x) fval := rval.Field(x) ftype := field.Type |
