aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-01-23 03:40:50 +0700
committerShulhan <ms@kilabit.info>2025-01-23 03:41:10 +0700
commit2a0694d2fa577574b505c4635eb8a824eaf88ddc (patch)
treecce840739c7f59893c3a6a65a1600f9f857c484e
parent605d847b236dde031a2e387e74298d66a27b5e0a (diff)
downloadpakakeh.go-2a0694d2fa577574b505c4635eb8a824eaf88ddc.tar.xz
all: use for-range with numeric
Go 1.22 now support for-range on numeric value.
-rw-r--r--lib/ascii/ascii.go12
-rw-r--r--lib/bytes/bytes.go8
-rw-r--r--lib/dns/answers.go8
-rw-r--r--lib/dns/caches.go12
-rw-r--r--lib/dns/caches_test.go9
-rw-r--r--lib/dns/message.go32
-rw-r--r--lib/dns/message_question.go3
-rw-r--r--lib/dns/rdata_svcb.go3
-rw-r--r--lib/dns/resource_record.go8
-rw-r--r--lib/dns/server.go12
-rw-r--r--lib/dns/udp_client_pool.go8
-rw-r--r--lib/dns/udp_client_pool_test.go9
-rw-r--r--lib/dns/zone_parser.go14
-rw-r--r--lib/dsv/reader_test.go8
-rw-r--r--lib/email/body.go9
-rw-r--r--lib/email/contenttype.go10
-rw-r--r--lib/email/dkim/func.go9
-rw-r--r--lib/email/dkim/hashalg.go8
-rw-r--r--lib/email/dkim/keyflag.go8
-rw-r--r--lib/email/dkim/signature.go14
-rw-r--r--lib/email/dkim/tag.go10
-rw-r--r--lib/email/field.go8
-rw-r--r--lib/email/is.go8
-rw-r--r--lib/email/message.go2
-rw-r--r--lib/git/git.go10
-rw-r--r--lib/hexdump/hexdump.go5
-rw-r--r--lib/http/cors_options.go8
-rw-r--r--lib/hunspell/flags.go13
-rw-r--r--lib/hunspell/hunspell.go11
-rw-r--r--lib/hunspell/options.go8
-rw-r--r--lib/hunspell/tests/morphology.go9
-rw-r--r--lib/ini/common_test.go9
-rw-r--r--lib/ini/ini.go15
-rw-r--r--lib/ini/section.go16
-rw-r--r--lib/ini/tag_struct_field.go8
-rw-r--r--lib/json/json.go8
-rw-r--r--lib/memfs/memfs.go3
-rw-r--r--lib/memfs/node.go2
-rw-r--r--lib/mining/classifier/cart/cart.go2
-rw-r--r--lib/mining/classifier/cm.go12
-rw-r--r--lib/mining/classifier/crf/crf.go8
-rw-r--r--lib/mining/classifier/stats_interface.go12
-rw-r--r--lib/mining/resampling/lnsmote/lnsmote.go8
-rw-r--r--lib/mining/resampling/smote/smote.go8
-rw-r--r--lib/mlog/mlog_test.go10
-rw-r--r--lib/mlog/multi_logger.go4
-rw-r--r--lib/net/net.go12
-rw-r--r--lib/net/poll_bsd.go12
-rw-r--r--lib/net/poll_linux.go12
-rw-r--r--lib/os/os.go8
-rw-r--r--lib/paseto/paseto.go8
-rw-r--r--lib/reflect/example_test.go3
-rw-r--r--lib/reflect/reflect.go4
-rw-r--r--lib/runes/runes.go9
-rw-r--r--lib/slices/slices.go4
-rw-r--r--lib/slices/slices_int_test.go2
-rw-r--r--lib/smtp/account.go8
-rw-r--r--lib/smtp/smtp.go12
-rw-r--r--lib/spf/macro.go9
-rw-r--r--lib/spf/result.go8
-rw-r--r--lib/sshconfig/parser.go10
-rw-r--r--lib/sshconfig/section_match.go9
-rw-r--r--lib/strings/parser_test.go8
-rw-r--r--lib/strings/row.go8
-rw-r--r--lib/strings/strings.go26
-rw-r--r--lib/strings/table.go14
-rw-r--r--lib/strings/to.go4
-rw-r--r--lib/tabula/column.go6
-rw-r--r--lib/tabula/columns.go8
-rw-r--r--lib/tabula/dataset.go8
-rw-r--r--lib/test/mock/rand_reader_example_test.go9
-rw-r--r--lib/text/chunk.go8
-rw-r--r--lib/totp/totp.go8
-rw-r--r--lib/websocket/client_test.go8
-rw-r--r--lib/websocket/frame.go8
-rw-r--r--lib/websocket/websocket_test.go8
-rw-r--r--lib/xmlrpc/value.go4
77 files changed, 336 insertions, 350 deletions
diff --git a/lib/ascii/ascii.go b/lib/ascii/ascii.go
index 7ad70e79..58424bb6 100644
--- a/lib/ascii/ascii.go
+++ b/lib/ascii/ascii.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
// Package ascii provide a library for working with ASCII characters.
package ascii
@@ -60,7 +60,7 @@ func IsDigit(b byte) bool {
// IsDigits will return true if all bytes are ASCII digit, otherwise it will
// return false.
func IsDigits(data []byte) bool {
- for x := 0; x < len(data); x++ {
+ for x := range len(data) {
if !IsDigit(data[x]) {
return false
}
@@ -110,7 +110,7 @@ func Random(source []byte, n int) []byte {
// ToLower convert slice of ASCII characters to lower cases, in places, which
// means it will return the same slice instead of creating new one.
func ToLower(data []byte) []byte {
- for x := 0; x < len(data); x++ {
+ for x := range len(data) {
if data[x] < 'A' || data[x] > 'Z' {
continue
}
@@ -122,7 +122,7 @@ func ToLower(data []byte) []byte {
// ToUpper convert slice of ASCII characters to upper cases, in places, which
// means it will return the same slice instead of creating new one.
func ToUpper(data []byte) []byte {
- for x := 0; x < len(data); x++ {
+ for x := range len(data) {
if data[x] < 'a' || data[x] > 'z' {
continue
}
diff --git a/lib/bytes/bytes.go b/lib/bytes/bytes.go
index ae1c9234..f0f55555 100644
--- a/lib/bytes/bytes.go
+++ b/lib/bytes/bytes.go
@@ -154,9 +154,9 @@ func InReplace(text, allowed []byte, c byte) []byte {
}
var found bool
- for x := 0; x < len(text); x++ {
+ for x := range len(text) {
found = false
- for y := 0; y < len(allowed); y++ {
+ for y := range len(allowed) {
if text[x] == allowed[y] {
found = true
break
@@ -207,7 +207,7 @@ func IsTokenAt(text, token []byte, p int) bool {
return false
}
- for x := 0; x < tokenlen; x++ {
+ for x := range tokenlen {
if text[p] != token[x] {
return false
}
@@ -370,7 +370,7 @@ func SplitEach(data []byte, n int) (chunks [][]byte) {
rows = (size / n)
total int
)
- for x := 0; x < rows; x++ {
+ for range rows {
chunks = append(chunks, data[total:total+n])
total += n
}
diff --git a/lib/dns/answers.go b/lib/dns/answers.go
index 30587633..a29fdf86 100644
--- a/lib/dns/answers.go
+++ b/lib/dns/answers.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package dns
@@ -25,7 +25,7 @@ func newAnswers(an *Answer) (ans *answers) {
// If found, it will return its element and index in slice; otherwise it will
// return nil on answer.
func (ans *answers) get(rtype RecordType, rclass RecordClass) (an *Answer, x int) {
- for x = 0; x < len(ans.v); x++ {
+ for ; x < len(ans.v); x++ {
if ans.v[x].RType != rtype {
continue
}
diff --git a/lib/dns/caches.go b/lib/dns/caches.go
index d0c674c7..3d4d5142 100644
--- a/lib/dns/caches.go
+++ b/lib/dns/caches.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package dns
@@ -349,14 +349,10 @@ func (c *Caches) InternalPopulateZone(zone *Zone) {
// InternalRemoveNames remove internal caches by domain names.
func (c *Caches) InternalRemoveNames(names []string) {
- var (
- x int
- )
-
c.Lock()
defer c.Unlock()
- for ; x < len(names); x++ {
+ for x := range len(names) {
delete(c.internal, names[x])
if c.debug&DebugLevelCache != 0 {
log.Println(`dns: - `, names[x])
diff --git a/lib/dns/caches_test.go b/lib/dns/caches_test.go
index 4f15d3d0..3dc64fbd 100644
--- a/lib/dns/caches_test.go
+++ b/lib/dns/caches_test.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package dns
@@ -284,7 +284,6 @@ func TestCachesUpsert(t *testing.T) {
cases []testCase
c testCase
gotList []*Answer
- x int
)
ca.init(0, 0, 0)
@@ -322,7 +321,7 @@ func TestCachesUpsert(t *testing.T) {
test.Assert(t, "len(caches.list)", c.expLen, len(gotList))
- for x = 0; x < len(gotList); x++ {
+ for x := range len(gotList) {
test.Assert(t, "caches.list", c.expList[x], gotList[x])
}
}
diff --git a/lib/dns/message.go b/lib/dns/message.go
index d3d55b01..abef69cd 100644
--- a/lib/dns/message.go
+++ b/lib/dns/message.go
@@ -189,9 +189,8 @@ func UnpackMessage(packet []byte) (msg *Message, err error) {
startIdx = uint(sectionHeaderSize + msg.Question.size())
rr ResourceRecord
- x uint16
)
- for ; x < msg.Header.ANCount; x++ {
+ for range msg.Header.ANCount {
rr = ResourceRecord{}
startIdx, err = rr.unpack(msg.packet, startIdx)
@@ -202,7 +201,7 @@ func UnpackMessage(packet []byte) (msg *Message, err error) {
msg.Answer = append(msg.Answer, rr)
}
- for x = 0; x < msg.Header.NSCount; x++ {
+ for range msg.Header.NSCount {
rr = ResourceRecord{}
startIdx, err = rr.unpack(msg.packet, startIdx)
@@ -212,7 +211,7 @@ func UnpackMessage(packet []byte) (msg *Message, err error) {
msg.Authority = append(msg.Authority, rr)
}
- for x = 0; x < msg.Header.ARCount; x++ {
+ for range msg.Header.ARCount {
rr = ResourceRecord{}
startIdx, err = rr.unpack(msg.packet, startIdx)
@@ -380,8 +379,7 @@ func (msg *Message) packDomainName(dname []byte, doCompress bool) (n int) {
idxCount = len(msg.packet) - 1
msg.dnameOff[msg.dname] = uint16(idxCount)
n++
-
- for x = 0; x < len(dname); x++ {
+ for ; x < len(dname); x++ {
c = dname[x]
if c == '\\' {
@@ -852,7 +850,7 @@ func (msg *Message) IsExpired() bool {
x int
)
- for x = 0; x < len(msg.Answer); x++ {
+ for x = range len(msg.Answer) {
if msg.Answer[x].TTL == 0 {
return true
}
@@ -861,7 +859,7 @@ func (msg *Message) IsExpired() bool {
return false
}
- for x = 0; x < len(msg.Authority); x++ {
+ for x = range len(msg.Authority) {
if msg.Authority[x].TTL == 0 {
return true
}
@@ -895,13 +893,13 @@ func (msg *Message) Pack() ([]byte, error) {
return msg.packet, nil
}
- for x = 0; x < len(msg.Answer); x++ {
+ for x = range len(msg.Answer) {
msg.packRR(&msg.Answer[x])
}
- for x = 0; x < len(msg.Authority); x++ {
+ for x = range len(msg.Authority) {
msg.packRR(&msg.Authority[x])
}
- for x = 0; x < len(msg.Additional); x++ {
+ for x = range len(msg.Additional) {
msg.packRR(&msg.Additional[x])
}
@@ -1005,7 +1003,7 @@ func (msg *Message) SubTTL(n uint32) {
x int
)
- for x = 0; x < len(msg.Answer); x++ {
+ for x = range len(msg.Answer) {
if msg.Answer[x].TTL < n {
msg.Answer[x].TTL = 0
} else {
@@ -1015,7 +1013,7 @@ func (msg *Message) SubTTL(n uint32) {
msg.packet[msg.Answer[x].idxTTL:],
msg.Answer[x].TTL)
}
- for x = 0; x < len(msg.Authority); x++ {
+ for x = range len(msg.Authority) {
if msg.Authority[x].TTL < n {
msg.Authority[x].TTL = 0
} else {
@@ -1025,7 +1023,7 @@ func (msg *Message) SubTTL(n uint32) {
msg.packet[msg.Authority[x].idxTTL:],
msg.Authority[x].TTL)
}
- for x = 0; x < len(msg.Additional); x++ {
+ for x = range len(msg.Additional) {
if msg.Additional[x].Type == RecordTypeOPT {
continue
}
@@ -1050,7 +1048,7 @@ func (msg *Message) String() string {
fmt.Fprintf(&b, "{Header:%+v Question:%+v", msg.Header, msg.Question)
b.WriteString(" Answer:[")
- for x = 0; x < len(msg.Answer); x++ {
+ for x = range len(msg.Answer) {
if x > 0 {
b.WriteByte(' ')
}
@@ -1059,7 +1057,7 @@ func (msg *Message) String() string {
b.WriteString("]")
b.WriteString(" Authority:[")
- for x = 0; x < len(msg.Authority); x++ {
+ for x = range len(msg.Authority) {
if x > 0 {
b.WriteByte(' ')
}
@@ -1068,7 +1066,7 @@ func (msg *Message) String() string {
b.WriteString("]")
b.WriteString(" Additional:[")
- for x = 0; x < len(msg.Additional); x++ {
+ for x = range len(msg.Additional) {
if x > 0 {
b.WriteByte(' ')
}
diff --git a/lib/dns/message_question.go b/lib/dns/message_question.go
index b0be7018..c345880b 100644
--- a/lib/dns/message_question.go
+++ b/lib/dns/message_question.go
@@ -60,7 +60,6 @@ func (qst *MessageQuestion) unpack(packet []byte) (err error) {
logp = "MessageQuestion.unpack"
sb strings.Builder
x int
- y int
count int
)
@@ -76,7 +75,7 @@ func (qst *MessageQuestion) unpack(packet []byte) (err error) {
if sb.Len() > 0 {
sb.WriteByte('.')
}
- for y = 0; y < count; y++ {
+ for range count {
x++
if packet[x] >= 'A' && packet[x] <= 'Z' {
sb.WriteByte(packet[x] + 32)
diff --git a/lib/dns/rdata_svcb.go b/lib/dns/rdata_svcb.go
index 75099b55..1f3104ea 100644
--- a/lib/dns/rdata_svcb.go
+++ b/lib/dns/rdata_svcb.go
@@ -908,10 +908,9 @@ func svcbEncodeValue(in string) (out string, escaped bool) {
func svcbSplitRawValue(raw []byte) (listValue []string, err error) {
var (
val []byte
- x int
isEsc bool
)
- for ; x < len(raw); x++ {
+ for x := range len(raw) {
if isEsc {
switch raw[x] {
case '\\':
diff --git a/lib/dns/resource_record.go b/lib/dns/resource_record.go
index 88047f1d..f90cc85c 100644
--- a/lib/dns/resource_record.go
+++ b/lib/dns/resource_record.go
@@ -231,9 +231,9 @@ func unpackDomainName(packet []byte, start uint) (name string, end uint, err err
logp = `unpackDomainName`
x = int(start)
- out strings.Builder
- count, y byte
- isJump bool
+ out strings.Builder
+ count byte
+ isJump bool
)
end = start
@@ -272,7 +272,7 @@ func unpackDomainName(packet []byte, start uint) (name string, end uint, err err
if out.Len() > 0 {
out.WriteByte('.')
}
- for y = 0; y < count; y++ {
+ for range count {
if packet[x] >= 'A' && packet[x] <= 'Z' {
out.WriteByte(packet[x] + 32)
} else {
diff --git a/lib/dns/server.go b/lib/dns/server.go
index 9d341dac..7eb8fea6 100644
--- a/lib/dns/server.go
+++ b/lib/dns/server.go
@@ -725,22 +725,22 @@ func (srv *Server) startAllForwarders() {
x int
)
- for x = 0; x < len(srv.opts.primaryUDP); x++ {
+ for x = range len(srv.opts.primaryUDP) {
tag = fmt.Sprintf("UDP-%d-%s", x, asPrimary)
nameserver = srv.opts.primaryUDP[x].String()
go srv.udpForwarder(tag, nameserver)
}
- for x = 0; x < len(srv.opts.primaryTCP); x++ {
+ for x = range len(srv.opts.primaryTCP) {
tag = fmt.Sprintf("TCP-%d-%s", x, asPrimary)
nameserver = srv.opts.primaryTCP[x].String()
go srv.tcpForwarder(tag, nameserver)
}
- for x = 0; x < len(srv.opts.primaryDoh); x++ {
+ for x = range len(srv.opts.primaryDoh) {
tag = fmt.Sprintf("DoH-%d-%s", x, asPrimary)
nameserver = srv.opts.primaryDoh[x]
go srv.dohForwarder(tag, nameserver)
}
- for x = 0; x < len(srv.opts.primaryDot); x++ {
+ for x = range len(srv.opts.primaryDot) {
tag = fmt.Sprintf("DoT-%d-%s", x, asPrimary)
nameserver = srv.opts.primaryDot[x]
go srv.tlsForwarder(tag, nameserver)
@@ -1068,10 +1068,10 @@ func (srv *Server) stopAllForwarders() {
var (
x int
)
- for x = 0; x < len(srv.fwStoppers); x++ {
+ for x = range len(srv.fwStoppers) {
srv.fwStoppers[x] <- true
}
- for x = 0; x < len(srv.fwStoppers); x++ {
+ for x = range len(srv.fwStoppers) {
close(srv.fwStoppers[x])
}
diff --git a/lib/dns/udp_client_pool.go b/lib/dns/udp_client_pool.go
index 4b0a75de..6b4e4a54 100644
--- a/lib/dns/udp_client_pool.go
+++ b/lib/dns/udp_client_pool.go
@@ -41,16 +41,12 @@ func NewUDPClientPool(nameServers []string) (ucp *UDPClientPool, err error) {
New: ucp.newClient,
}
- var (
- cl *UDPClient
- x int
- )
-
// Create new client for each name server, and push it to pool.
// This is required to check if each name server is a valid IP
// address because we did not want the New method return nil client
// later.
- for x = 0; x < len(nameServers); x++ {
+ for x := range len(nameServers) {
+ var cl *UDPClient
cl, err = NewUDPClient(nameServers[x])
if err != nil {
return nil, err
diff --git a/lib/dns/udp_client_pool_test.go b/lib/dns/udp_client_pool_test.go
index a238d3d7..88e52d75 100644
--- a/lib/dns/udp_client_pool_test.go
+++ b/lib/dns/udp_client_pool_test.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package dns
@@ -27,7 +27,6 @@ func TestNewUDPClientPool(t *testing.T) {
qname string
err error
- x int
)
cases = []testCase{{
@@ -57,7 +56,7 @@ func TestNewUDPClientPool(t *testing.T) {
}
qname = "kilabit.info"
- for x = 0; x < 10; x++ {
+ for range 10 {
wg.Add(1)
go func() {
var (
diff --git a/lib/dns/zone_parser.go b/lib/dns/zone_parser.go
index b5f5d260..29128370 100644
--- a/lib/dns/zone_parser.go
+++ b/lib/dns/zone_parser.go
@@ -1052,7 +1052,7 @@ func (m *zoneParser) decodeString(in []byte) (out []byte, err error) {
}
var x int
- for x = 0; x < size; x++ {
+ for ; x < size; x++ {
c = in[x]
if ascii.IsSpace(c) {
break
@@ -1118,23 +1118,19 @@ func (m *zoneParser) push(rr *ResourceRecord) error {
}
func (m *zoneParser) setMinimumTTL() {
- var (
- msg *Message
- x int
- )
-
+ var msg *Message
for _, msg = range m.zone.messages {
- for x = 0; x < len(msg.Answer); x++ {
+ for x := range len(msg.Answer) {
if msg.Answer[x].TTL < m.zone.SOA.Minimum {
msg.Answer[x].TTL = m.zone.SOA.Minimum
}
}
- for x = 0; x < len(msg.Authority); x++ {
+ for x := range len(msg.Authority) {
if msg.Authority[x].TTL < m.zone.SOA.Minimum {
msg.Authority[x].TTL = m.zone.SOA.Minimum
}
}
- for x = 0; x < len(msg.Additional); x++ {
+ for x := range len(msg.Additional) {
if msg.Additional[x].TTL < m.zone.SOA.Minimum {
msg.Additional[x].TTL = m.zone.SOA.Minimum
}
diff --git a/lib/dsv/reader_test.go b/lib/dsv/reader_test.go
index 5d48b552..12763399 100644
--- a/lib/dsv/reader_test.go
+++ b/lib/dsv/reader_test.go
@@ -1,6 +1,6 @@
-// Copyright 2015-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: 2015 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package dsv
@@ -445,7 +445,7 @@ func TestSplitRowsByValue(t *testing.T) {
// test left split
exp := ""
- for x := 0; x < 4; x++ {
+ for x := range 4 {
exp += expectation[x]
}
diff --git a/lib/email/body.go b/lib/email/body.go
index 0dd6dda4..a619a2f7 100644
--- a/lib/email/body.go
+++ b/lib/email/body.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package email
@@ -195,7 +195,8 @@ func (body *Body) Relaxed() (out []byte) {
// Reduce sequence of WSP.
end := x
hasSpace := 0
- for x = 0; x <= end; x++ {
+ x = 0
+ for ; x <= end; x++ {
if body.raw[x] == '\t' || body.raw[x] == ' ' || body.raw[x] == '\n' {
hasSpace++
continue
diff --git a/lib/email/contenttype.go b/lib/email/contenttype.go
index 01f1cc06..8fdbff14 100644
--- a/lib/email/contenttype.go
+++ b/lib/email/contenttype.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package email
@@ -121,7 +121,7 @@ func isValidToken(tok []byte, quoted bool) bool {
if len(tok) == 0 {
return false
}
- for x := 0; x < len(tok); x++ {
+ for x := range len(tok) {
if quoted && tok[x] == ' ' {
continue
}
@@ -164,7 +164,7 @@ func (ct *ContentType) isEqual(other *ContentType) bool {
// SetBoundary set or replace the Value for Key "boundary".
func (ct *ContentType) SetBoundary(boundary string) {
- for x := 0; x < len(ct.Params); x++ {
+ for x := range len(ct.Params) {
if strings.EqualFold(ct.Params[x].Key, ParamNameBoundary) {
ct.Params[x].Value = boundary
return
diff --git a/lib/email/dkim/func.go b/lib/email/dkim/func.go
index bd778766..dae52bbe 100644
--- a/lib/email/dkim/func.go
+++ b/lib/email/dkim/func.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package dkim
@@ -17,7 +17,8 @@ func DecodeQP(raw []byte) (out []byte) {
out = make([]byte, 0, len(raw))
- for x := 0; x < len(raw); x++ {
+ var x int
+ for ; x < len(raw); x++ {
if ascii.IsSpace(raw[x]) {
continue
}
diff --git a/lib/email/dkim/hashalg.go b/lib/email/dkim/hashalg.go
index 280ab144..b856f82d 100644
--- a/lib/email/dkim/hashalg.go
+++ b/lib/email/dkim/hashalg.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package dkim
@@ -26,7 +26,7 @@ var hashAlgNames = map[HashAlg][]byte{
func unpackHashAlgs(v []byte) (hashAlgs []HashAlg) {
algs := bytes.Split(v, sepColon)
- for x := 0; x < len(algs); x++ {
+ for x := range len(algs) {
for k, v := range hashAlgNames {
if bytes.Equal(v, algs[x]) {
hashAlgs = append(hashAlgs, k)
diff --git a/lib/email/dkim/keyflag.go b/lib/email/dkim/keyflag.go
index a4cd1c44..6e950a6f 100644
--- a/lib/email/dkim/keyflag.go
+++ b/lib/email/dkim/keyflag.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package dkim
@@ -31,7 +31,7 @@ var keyFlagNames = map[KeyFlag]byte{
func unpackKeyFlags(in []byte) (out []KeyFlag) {
flags := bytes.Split(in, sepColon)
- for x := 0; x < len(flags); x++ {
+ for x := range len(flags) {
if len(flags[x]) != 1 {
continue
}
diff --git a/lib/email/dkim/signature.go b/lib/email/dkim/signature.go
index fb155753..6d3129c0 100644
--- a/lib/email/dkim/signature.go
+++ b/lib/email/dkim/signature.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package dkim
@@ -207,7 +207,7 @@ func (sig *Signature) Pack(simple bool) []byte {
if len(sig.PresentHeaders) > 0 {
bb.WriteString("z=")
- for x := 0; x < len(sig.PresentHeaders); x++ {
+ for x := range len(sig.PresentHeaders) {
if x > 0 {
bb.WriteByte('|')
wrap(bb, simple)
@@ -422,7 +422,7 @@ func (sig *Signature) set(t *tag) (err error) {
return errEmptyHeader
}
headers := bytes.Split(t.value, sepColon)
- for x := 0; x < len(headers); x++ {
+ for x := range len(headers) {
headers[x] = bytes.ToLower(bytes.TrimSpace(headers[x]))
sig.Headers = append(sig.Headers, headers[x])
}
@@ -464,7 +464,7 @@ func (sig *Signature) set(t *tag) (err error) {
case tagPresentHeaders:
z := bytes.Split(t.value, sepVBar)
- for x := 0; x < len(z); x++ {
+ for x := range len(z) {
z[x] = bytes.TrimSpace(z[x])
sig.PresentHeaders = append(sig.PresentHeaders, z[x])
}
@@ -554,7 +554,7 @@ func (sig *Signature) setQueryMethod(qtype, qopt []byte) (err error) {
// validateHeaders validate value of header tag "h=" that it MUST contains
// "from".
func (sig *Signature) validateHeaders() (err error) {
- for x := 0; x < len(sig.Headers); x++ {
+ for x := range len(sig.Headers) {
if bytes.Equal(sig.Headers[x], []byte("from")) {
return nil
}
diff --git a/lib/email/dkim/tag.go b/lib/email/dkim/tag.go
index ce1d895d..22931bc8 100644
--- a/lib/email/dkim/tag.go
+++ b/lib/email/dkim/tag.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package dkim
@@ -94,7 +94,7 @@ func newTag(key []byte) (t *tag, err error) {
if !ascii.IsAlpha(key[0]) {
return nil, fmt.Errorf("dkim: invalid tag key: '%s'", key)
}
- for x := 0; x < len(key); x++ {
+ for x := range len(key) {
if ascii.IsAlnum(key[x]) || key[x] == '_' {
continue
}
@@ -126,7 +126,7 @@ func (t *tag) setValue(val []byte) (err error) {
if t.key == tagSignature || t.key == tagBodyHash || t.key == tagDNSPublicKey {
isBase64 = true
}
- for x := 0; x < len(val); x++ {
+ for x := range len(val) {
switch {
case ascii.IsSpace(val[x]):
continue
diff --git a/lib/email/field.go b/lib/email/field.go
index 77cd9d92..05492548 100644
--- a/lib/email/field.go
+++ b/lib/email/field.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package email
@@ -219,7 +219,7 @@ func (field *Field) addMailboxes(mailboxes []byte) (err error) {
func relaxedName(raw []byte) (rel []byte) {
rel = make([]byte, 0, len(raw))
- for x := 0; x < len(raw); x++ {
+ for x := range len(raw) {
if raw[x] == ' ' || raw[x] < 33 || raw[x] > 126 {
break
}
diff --git a/lib/email/is.go b/lib/email/is.go
index 6abeb045..b5f2d09b 100644
--- a/lib/email/is.go
+++ b/lib/email/is.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package email
@@ -26,7 +26,7 @@ func IsValidLocal(local []byte) bool {
return false
}
dot := false
- for x := 0; x < len(local); x++ {
+ for x := range len(local) {
if local[x] < 33 || local[x] > 126 {
return false
}
diff --git a/lib/email/message.go b/lib/email/message.go
index 55ade647..f12d3134 100644
--- a/lib/email/message.go
+++ b/lib/email/message.go
@@ -448,7 +448,7 @@ func (msg *Message) CanonHeader(subHeader *Header, dkimField *Field) []byte {
canonType = dkim.CanonSimple
}
- for x := 0; x < len(msg.DKIMSignature.Headers); x++ {
+ for x := range len(msg.DKIMSignature.Headers) {
signedField := subHeader.popByName(string(msg.DKIMSignature.Headers[x]))
if signedField == nil {
continue
diff --git a/lib/git/git.go b/lib/git/git.go
index 151e077a..71240221 100644
--- a/lib/git/git.go
+++ b/lib/git/git.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 git provide a wrapper for git command line interface.
package git
@@ -280,7 +280,7 @@ func ListTags(repoDir string) (tags []string, err error) {
sep := []byte{'\n'}
btags := bytes.Split(bout, sep)
- for x := 0; x < len(btags); x++ {
+ for x := range len(btags) {
if len(btags[x]) == 0 {
continue
}
@@ -361,7 +361,7 @@ func RemoteBranches(repoDir string) ([]string, error) {
var branches []string
bHEAD := []byte("HEAD")
- for x := 0; x < len(bbranches); x++ {
+ for x := range len(bbranches) {
if len(bbranches[x]) == 0 {
continue
}
diff --git a/lib/hexdump/hexdump.go b/lib/hexdump/hexdump.go
index 50c0a3ce..d333f32a 100644
--- a/lib/hexdump/hexdump.go
+++ b/lib/hexdump/hexdump.go
@@ -44,7 +44,6 @@ func Parse(in []byte, networkByteOrder bool) (out []byte, err error) {
token []byte
vint64 int64
- x int
isAsterisk bool
)
for d != 0 {
@@ -78,14 +77,14 @@ func Parse(in []byte, networkByteOrder bool) (out []byte, err error) {
prevRow = out[start:]
identicalRow = int((vint64 - int64(len(out))) / 16)
)
- for x = 0; x < identicalRow; x++ {
+ for range identicalRow {
out = append(out, prevRow...)
}
}
}
// Read the two-hex, 16-bit words.
- for x = 0; x < 8; x++ {
+ for range 8 {
token, d = parser.Read()
if len(token) == 0 {
break
diff --git a/lib/http/cors_options.go b/lib/http/cors_options.go
index c1151556..f67ca586 100644
--- a/lib/http/cors_options.go
+++ b/lib/http/cors_options.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 http
@@ -121,7 +121,7 @@ func (cors *CORSOptions) handleRequestHeaders(res http.ResponseWriter, req *http
reqHeaders = strings.Split(preflightHeaders, `,`)
x int
)
- for x = 0; x < len(reqHeaders); x++ {
+ for x = range len(reqHeaders) {
reqHeaders[x] = strings.ToLower(strings.TrimSpace(reqHeaders[x]))
}
diff --git a/lib/hunspell/flags.go b/lib/hunspell/flags.go
index 7324e1cf..1c725b6d 100644
--- a/lib/hunspell/flags.go
+++ b/lib/hunspell/flags.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package hunspell
@@ -32,7 +32,7 @@ func unpackFlags(ftype, rawflags string) (flags []string, err error) {
}
func unpackFlagASCII(f string) (flags []string) {
- for x := 0; x < len(f); x++ {
+ for x := range len(f) {
flags = append(flags, string(f[x]))
}
return
@@ -49,7 +49,8 @@ func unpackFlagLong(f string) (flags []string, err error) {
if len(f)%2 != 0 {
return nil, fmt.Errorf("invalid long flags: %q", f)
}
- for x := 0; x < len(f); x += 2 {
+ var x int
+ for ; x < len(f); x += 2 {
flags = append(flags, f[x:x+2])
}
return
@@ -59,7 +60,7 @@ func unpackFlagNum(f string) (flags []string, err error) {
flags = strings.Split(f, ",")
// Trim spaces and check if all the flags is valid number.
- for x := 0; x < len(flags); x++ {
+ for x := range len(flags) {
flags[x] = strings.TrimSpace(flags[x])
_, err = strconv.Atoi(flags[x])
diff --git a/lib/hunspell/hunspell.go b/lib/hunspell/hunspell.go
index eb813bb8..d8ed8bd6 100644
--- a/lib/hunspell/hunspell.go
+++ b/lib/hunspell/hunspell.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
// Package hunspell is a library to parse the Hunspell file format.
package hunspell
@@ -181,10 +181,9 @@ func MergeDictionaries(outFile string, inFiles ...string) (n int, err error) {
dict = make(map[string]string, 1024)
lines []string
- x int
)
- for x = 0; x < len(inFiles); x++ {
+ for x := range len(inFiles) {
lines, err = libstrings.LinesOfFile(inFiles[x])
if err != nil {
return 0, err
@@ -222,7 +221,7 @@ func MergeDictionaries(outFile string, inFiles ...string) (n int, err error) {
}
fmt.Fprintf(fout, "%d\n", len(words))
- for x := 0; x < len(words); x++ {
+ for x := range len(words) {
fmt.Fprintf(fout, "%s\n", words[x])
}
diff --git a/lib/hunspell/options.go b/lib/hunspell/options.go
index 9386c574..4de0de09 100644
--- a/lib/hunspell/options.go
+++ b/lib/hunspell/options.go
@@ -1,6 +1,6 @@
-// Copyright 2020, 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: 2020 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package hunspell
@@ -163,7 +163,7 @@ func (opts *affixOptions) load(content string) (err error) {
lines := p.Lines()
- for x := 0; x < len(lines); x++ {
+ for x := range len(lines) {
// Skip comment, a line starting with '#'.
if lines[x][0] == '#' {
continue
diff --git a/lib/hunspell/tests/morphology.go b/lib/hunspell/tests/morphology.go
index 3df2cb4a..f977db25 100644
--- a/lib/hunspell/tests/morphology.go
+++ b/lib/hunspell/tests/morphology.go
@@ -1,6 +1,6 @@
-// Copyright 2020, 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: 2020 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package tests
@@ -34,7 +34,8 @@ func parseMorphologiesFile(morphFile string) (morphs map[string]morphology, err
morph := &morphology{}
- for x := 0; x < len(lines); {
+ var x int
+ for x < len(lines) {
line := lines[x]
switch state {
case stateWord:
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
diff --git a/lib/json/json.go b/lib/json/json.go
index 84df191d..ee76c449 100644
--- a/lib/json/json.go
+++ b/lib/json/json.go
@@ -40,7 +40,7 @@ const (
func Escape(in []byte) []byte {
var buf bytes.Buffer
- for x := 0; x < len(in); x++ {
+ for x := range len(in) {
if in[x] == bDoubleQuote || in[x] == bRevSolidus {
buf.WriteByte(bRevSolidus)
buf.WriteByte(in[x])
@@ -169,13 +169,15 @@ func Unescape(in []byte, strict bool) (out []byte, err error) {
esc bool
)
- for x := 0; x < len(in); x++ {
+ var x int
+ for ; x < len(in); x++ {
if esc {
if in[x] == 'u' {
uni.Reset()
x++
- for y := 0; y < 4 && x < len(in); x++ {
+ var y int
+ for ; y < 4 && x < len(in); x++ {
uni.WriteByte(in[x])
y++
}
diff --git a/lib/memfs/memfs.go b/lib/memfs/memfs.go
index e80b7e58..9e02fc95 100644
--- a/lib/memfs/memfs.go
+++ b/lib/memfs/memfs.go
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2018 M. Shulhan <ms@kilabit.info>
+//
// SPDX-License-Identifier: BSD-3-Clause
package memfs
@@ -335,7 +336,7 @@ func (mfs *MemFS) Search(words []string, snippetLen int) (results []SearchResult
}
tokens := libstrings.ToBytes(words)
- for x := 0; x < len(tokens); x++ {
+ for x := range len(tokens) {
tokens[x] = bytes.ToLower(tokens[x])
}
diff --git a/lib/memfs/node.go b/lib/memfs/node.go
index ab75be68..7c04ff63 100644
--- a/lib/memfs/node.go
+++ b/lib/memfs/node.go
@@ -454,7 +454,7 @@ func (node *Node) removeChild(child *Node) *Node {
if child == nil {
return nil
}
- for x := 0; x < len(node.Childs); x++ {
+ for x := range len(node.Childs) {
if node.Childs[x] != child {
continue
}
diff --git a/lib/mining/classifier/cart/cart.go b/lib/mining/classifier/cart/cart.go
index 2a26e71e..d72fb929 100644
--- a/lib/mining/classifier/cart/cart.go
+++ b/lib/mining/classifier/cart/cart.go
@@ -250,7 +250,7 @@ func (runtime *Runtime) SelectRandomFeature(claset tabula.ClasetInterface) {
// Select random features excluding feature in `excludeIdx`.
var pickedIdx []int
- for x := 0; x < runtime.NRandomFeature; x++ {
+ for range runtime.NRandomFeature {
idx := numbers.IntPickRandPositive(ncols, false, pickedIdx,
excludeIdx)
pickedIdx = append(pickedIdx, idx)
diff --git a/lib/mining/classifier/cm.go b/lib/mining/classifier/cm.go
index d84f75ff..48cf37b8 100644
--- a/lib/mining/classifier/cm.go
+++ b/lib/mining/classifier/cm.go
@@ -1,6 +1,6 @@
-// Copyright 2016 Mhd Sulhan <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: 2016 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package classifier
@@ -152,7 +152,7 @@ func (cm *CM) countNumeric(act, pred int64, actuals, predictions []int64) (
minlen = len(predictions)
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
if actuals[x] != act {
continue
}
@@ -233,7 +233,7 @@ func (cm *CM) GroupIndexPredictions(sampleListID []int,
min = len(predictions)
}
- for x := 0; x < min; x++ {
+ for x := range min {
if actuals[x] == 1 {
if predictions[x] == 1 {
cm.tpListID = append(cm.tpListID, sampleListID[x])
@@ -275,7 +275,7 @@ func (cm *CM) GroupIndexPredictionsStrings(sampleListID []int,
min = len(predictions)
}
- for x := 0; x < min; x++ {
+ for x := range min {
if actuals[x] == "1" {
if predictions[x] == "1" {
cm.tpListID = append(cm.tpListID, sampleListID[x])
diff --git a/lib/mining/classifier/crf/crf.go b/lib/mining/classifier/crf/crf.go
index ceb9b605..91a470cf 100644
--- a/lib/mining/classifier/crf/crf.go
+++ b/lib/mining/classifier/crf/crf.go
@@ -1,6 +1,6 @@
-// Copyright 2016 Mhd Sulhan <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: 2016 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
// Package crf implement the cascaded random forest algorithm, proposed by
// Baumann et.al in their paper:
@@ -150,7 +150,7 @@ func (crf *Runtime) Build(samples tabula.ClasetInterface) (e error) {
fmt.Println(tag, "Sample (one row):", samples.GetRow(0))
fmt.Println(tag, "Config:", crf)
- for x := 0; x < crf.NStage; x++ {
+ for range crf.NStage {
forest, e := crf.createForest(samples)
if e != nil {
return e
diff --git a/lib/mining/classifier/stats_interface.go b/lib/mining/classifier/stats_interface.go
index f780d58b..38599d23 100644
--- a/lib/mining/classifier/stats_interface.go
+++ b/lib/mining/classifier/stats_interface.go
@@ -1,6 +1,6 @@
-// Copyright 2016 Mhd Sulhan <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: 2016 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package classifier
@@ -15,7 +15,7 @@ func ComputeFMeasures(precisions, recalls []float64) (fmeasures []float64) {
minlen = recallslen
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
f := 2 / ((1 / precisions[x]) + (1 / recalls[x]))
fmeasures = append(fmeasures, f)
}
@@ -38,7 +38,7 @@ func ComputeAccuracies(tp, fp, tn, fn []int64) (accuracies []float64) {
minlen = len(fn)
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
acc := float64(tp[x]+tn[x]) /
float64(tp[x]+fp[x]+tn[x]+fn[x])
accuracies = append(accuracies, acc)
@@ -55,7 +55,7 @@ func ComputeElapsedTimes(start, end []int64) (elaps []int64) {
minlen = len(end)
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
elaps = append(elaps, end[x]-start[x])
}
return
diff --git a/lib/mining/resampling/lnsmote/lnsmote.go b/lib/mining/resampling/lnsmote/lnsmote.go
index 524a4f54..4669446f 100644
--- a/lib/mining/resampling/lnsmote/lnsmote.go
+++ b/lib/mining/resampling/lnsmote/lnsmote.go
@@ -1,6 +1,6 @@
-// Copyright 2016 Mhd Sulhan <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: 2016 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
// Package lnsmote implement the Local-Neighborhood algorithm from the paper,
//
@@ -93,7 +93,7 @@ func (in *Runtime) Resampling(dataset tabula.DatasetInterface) (
neighbors := in.FindNeighbors(in.datasetRows, p)
- for y := 0; y < in.NSynthetic; y++ {
+ for range in.NSynthetic {
syn := in.createSynthetic(p, neighbors)
if syn != nil {
diff --git a/lib/mining/resampling/smote/smote.go b/lib/mining/resampling/smote/smote.go
index f2603731..2ba2827c 100644
--- a/lib/mining/resampling/smote/smote.go
+++ b/lib/mining/resampling/smote/smote.go
@@ -1,6 +1,6 @@
-// Copyright 2015 Mhd Sulhan <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: 2015 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
// Package smote resamples a dataset by applying the Synthetic Minority
// Oversampling TEchnique (SMOTE). The original dataset must fit entirely in
@@ -81,7 +81,7 @@ func (smote *Runtime) populate(instance *tabula.Row, neighbors knn.Neighbors) {
err error
)
- for x := 0; x < smote.NSynthetic; x++ {
+ for range smote.NSynthetic {
// choose one of the K nearest neighbors
randv, err = rand.Int(rand.Reader, randMax)
if err != nil {
diff --git a/lib/mlog/mlog_test.go b/lib/mlog/mlog_test.go
index 1dd440d7..f704ae00 100644
--- a/lib/mlog/mlog_test.go
+++ b/lib/mlog/mlog_test.go
@@ -1,6 +1,6 @@
-// Copyright 2022, 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: 2022 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package mlog
@@ -29,7 +29,7 @@ func TestMultiLogger_Close(_ *testing.T) {
go func() {
var x int
- for x = 0; x < 10; x++ {
+ for x = range 10 {
mlog.Outf("out: %d", x)
if x == 2 {
outq <- struct{}{}
@@ -39,7 +39,7 @@ func TestMultiLogger_Close(_ *testing.T) {
}()
go func() {
var x int
- for x = 0; x < 10; x++ {
+ for x = range 10 {
mlog.Errf("err: %d", x)
if x == 2 {
errq <- struct{}{}
diff --git a/lib/mlog/multi_logger.go b/lib/mlog/multi_logger.go
index 899bc304..9e1e37bd 100644
--- a/lib/mlog/multi_logger.go
+++ b/lib/mlog/multi_logger.go
@@ -94,10 +94,8 @@ func flush(qlog chan []byte, writers map[string]NamedWriter) {
err error
nw NamedWriter
b []byte
- x int
)
-
- for x = 0; x < len(qlog); x++ {
+ for range len(qlog) {
b = <-qlog
for name, nw = range writers {
_, err = nw.Write(b)
diff --git a/lib/net/net.go b/lib/net/net.go
index 4add0435..e52831d1 100644
--- a/lib/net/net.go
+++ b/lib/net/net.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 net provide constants and library for networking.
package net
@@ -176,14 +176,14 @@ func ToDotIPv6(ip net.IP) (out []byte) {
addrs := strings.Split(ip.String(), ":")
var notempty int
- for x := 0; x < len(addrs); x++ {
+ for x := range len(addrs) {
if len(addrs[x]) != 0 {
notempty++
}
}
gap := 8 - notempty
- for x := 0; x < len(addrs); x++ {
+ for x := range len(addrs) {
addr := addrs[x]
// Fill the gap "::" with one or more "0.0.0.0".
@@ -205,7 +205,7 @@ func ToDotIPv6(ip net.IP) (out []byte) {
out = append(out, '0')
}
- for y := 0; y < len(addr); y++ {
+ for y := range len(addr) {
if len(out) > 0 {
out = append(out, '.')
}
diff --git a/lib/net/poll_bsd.go b/lib/net/poll_bsd.go
index 80340fa7..668c3f58 100644
--- a/lib/net/poll_bsd.go
+++ b/lib/net/poll_bsd.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin || dragonfly || freebsd || netbsd || openbsd
@@ -81,7 +81,6 @@ func (poll *kqueue) WaitRead() (fds []int, err error) {
logp = `WaitRead`
n int
- x int
fd int
)
for n == 0 {
@@ -94,7 +93,7 @@ func (poll *kqueue) WaitRead() (fds []int, err error) {
}
}
- for x = 0; x < n; x++ {
+ for x := range n {
if poll.events[x].Filter != unix.EVFILT_READ {
continue
}
@@ -124,7 +123,6 @@ func (poll *kqueue) WaitReadEvents() (events []PollEvent, err error) {
logp = `WaitReadEvents`
n int
- x int
fd int
)
@@ -138,7 +136,7 @@ func (poll *kqueue) WaitReadEvents() (events []PollEvent, err error) {
}
}
- for x = 0; x < n; x++ {
+ for x := range n {
if poll.events[x].Filter != unix.EVFILT_READ {
continue
}
diff --git a/lib/net/poll_linux.go b/lib/net/poll_linux.go
index 69cf56b5..e10fe88b 100644
--- a/lib/net/poll_linux.go
+++ b/lib/net/poll_linux.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
//go:build linux
@@ -71,7 +71,6 @@ func (poll *epoll) WaitRead() (fds []int, err error) {
logp = `WaitRead`
n int
- x int
fd int
)
for {
@@ -85,7 +84,7 @@ func (poll *epoll) WaitRead() (fds []int, err error) {
break
}
- for x = 0; x < n; x++ {
+ for x := range n {
fd = int(poll.events[x].Fd)
err = poll.UnregisterRead(fd)
@@ -111,7 +110,6 @@ func (poll *epoll) WaitReadEvents() (events []PollEvent, err error) {
logp = `WaitReadEvents`
n int
- x int
fd int
)
@@ -126,7 +124,7 @@ func (poll *epoll) WaitReadEvents() (events []PollEvent, err error) {
break
}
- for x = 0; x < n; x++ {
+ for x := range n {
fd = int(poll.events[x].Fd)
err = poll.UnregisterRead(fd)
diff --git a/lib/os/os.go b/lib/os/os.go
index 0a3a0eab..3d6cbce9 100644
--- a/lib/os/os.go
+++ b/lib/os/os.go
@@ -1,6 +1,6 @@
-// Copyright 2022, 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: 2022 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
// Package os extend the standard os package to provide additional
// functionalities.
@@ -176,7 +176,7 @@ func IsBinary(file string) bool {
content = content[:n]
- for x = 0; x < len(content); x++ {
+ for x = range len(content) {
if ascii.IsSpace(content[x]) {
continue
}
diff --git a/lib/paseto/paseto.go b/lib/paseto/paseto.go
index 31fc8281..e37bcb2e 100644
--- a/lib/paseto/paseto.go
+++ b/lib/paseto/paseto.go
@@ -1,6 +1,6 @@
-// Copyright 2020, 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: 2020 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
// Package paseto provide a simple, ready to use, opinionated implementation
// of Platform-Agnostic SEcurity TOkens (PASETOs) v2 as defined in
@@ -323,7 +323,7 @@ func pae(pieces [][]byte) (b []byte, err error) {
return nil, err
}
- for x := 0; x < len(pieces); x++ {
+ for x := range len(pieces) {
err = binary.Write(&buf, binary.LittleEndian, uint64(len(pieces[x])))
if err != nil {
return nil, err
diff --git a/lib/reflect/example_test.go b/lib/reflect/example_test.go
index c0b028a3..69970fea 100644
--- a/lib/reflect/example_test.go
+++ b/lib/reflect/example_test.go
@@ -458,13 +458,12 @@ func ExampleTag() {
field reflect.StructField
val string
opts []string
- x int
hasTag bool
)
vtype = reflect.TypeOf(t)
- for x = 0; x < vtype.NumField(); x++ {
+ for x := range vtype.NumField() {
field = vtype.Field(x)
val, opts, hasTag = libreflect.Tag(field, "atag")
fmt.Println(val, opts, hasTag)
diff --git a/lib/reflect/reflect.go b/lib/reflect/reflect.go
index c3ff568c..2b344329 100644
--- a/lib/reflect/reflect.go
+++ b/lib/reflect/reflect.go
@@ -638,7 +638,7 @@ func doEqual(v1, v2 reflect.Value) (err error) {
if v1.Len() != v2.Len() {
return fmt.Errorf("len(%s): expecting %v, got %v", name1, v1.Len(), v2.Len())
}
- for x = 0; x < v1.Len(); x++ {
+ for x = range v1.Len() {
err = doEqual(v1.Index(x), v2.Index(x))
if err != nil {
return fmt.Errorf(`%s[%d]: %w`, name1, x, err)
@@ -707,7 +707,7 @@ func doEqual(v1, v2 reflect.Value) (err error) {
return fmt.Errorf("len(%s): expecting %v, got %v", name1, l1, l2)
}
- for x = 0; x < l1; x++ {
+ for x = range l1 {
s1 = v1.Index(x)
s2 = v2.Index(x)
err = doEqual(s1, s2)
diff --git a/lib/runes/runes.go b/lib/runes/runes.go
index b993028a..32b8885e 100644
--- a/lib/runes/runes.go
+++ b/lib/runes/runes.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 runes provide a library for working with a single rune or slice of
// rune.
@@ -107,7 +107,8 @@ func Inverse(in []rune) []rune {
left, right rune
y = len(in) - 1
)
- for x := 0; x < y; x++ {
+ var x int
+ for ; x < y; x++ {
left = in[x]
right = in[y]
in[x] = right
diff --git a/lib/slices/slices.go b/lib/slices/slices.go
index 70bfb7d7..d7dc19e7 100644
--- a/lib/slices/slices.go
+++ b/lib/slices/slices.go
@@ -263,7 +263,7 @@ func MinRange[S []E, E cmp.Ordered](slice S, l, r int) (v E, i int) {
// Remove val from slice if its exist and return new slice and true.
// Otherwise, if val not found, return unmodified slice and false.
func Remove[S []E, E comparable](slice S, v E) (S, bool) {
- for x := 0; x < len(slice); x++ {
+ for x := range len(slice) {
if slice[x] == v {
slice = append(slice[:x], slice[x+1:]...)
return slice, true
@@ -285,7 +285,7 @@ func SortByIndex[S []E, E cmp.Ordered](slice *S, sortedIdx []int) {
// Sum all value in slice.
func Sum[S []E, E constraints.Integer | constraints.Float](slice S) (sum E) {
- for x := 0; x < len(slice); x++ {
+ for x := range len(slice) {
sum += slice[x]
}
return sum
diff --git a/lib/slices/slices_int_test.go b/lib/slices/slices_int_test.go
index ebb327e0..2bd8423b 100644
--- a/lib/slices/slices_int_test.go
+++ b/lib/slices/slices_int_test.go
@@ -453,7 +453,7 @@ func generateRandomInts(data []int, n int) {
randv *big.Int
err error
)
- for x := 0; x < n; x++ {
+ for x := range n {
randv, err = rand.Int(rand.Reader, max)
if err != nil {
log.Fatalf(`generateRandomInts: %s`, err)
diff --git a/lib/smtp/account.go b/lib/smtp/account.go
index 5a4ed48f..542ab944 100644
--- a/lib/smtp/account.go
+++ b/lib/smtp/account.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package smtp
@@ -28,7 +28,7 @@ func NewAccount(name, local, domain, pass string) (acc *Account, err error) {
local = strings.ToLower(local)
if len(pass) > 0 {
- for x := 0; x < 3; x++ {
+ for range 3 {
hpass, err = bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost)
if err == nil {
break
diff --git a/lib/smtp/smtp.go b/lib/smtp/smtp.go
index eedbc930..f7121280 100644
--- a/lib/smtp/smtp.go
+++ b/lib/smtp/smtp.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 smtp
@@ -186,7 +186,8 @@ func parseLocalDomain(data []byte, allow []byte) (out []byte) {
found bool
isDot bool
)
- for x := 0; x < len(data); x++ {
+ var x int
+ for ; x < len(data); x++ {
if data[x] == '(' {
x = skipComment(data, x)
if x == len(data) {
@@ -250,7 +251,8 @@ func skipComment(data []byte, x int) int {
// %d32-126.
func parseQuotedMailbox(data []byte) (out []byte) {
out = append(out, '"')
- for x := 0; x < len(data); x++ {
+ var x int
+ for ; x < len(data); x++ {
if data[x] < 32 || data[x] == 34 || data[x] > 126 {
return nil
}
diff --git a/lib/spf/macro.go b/lib/spf/macro.go
index 4572f57e..14f56752 100644
--- a/lib/spf/macro.go
+++ b/lib/spf/macro.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package spf
@@ -108,7 +108,8 @@ func (m *macro) parse(data []byte) (err error) {
state byte
)
- for x := 0; x < len(data); x++ {
+ var x int
+ for ; x < len(data); x++ {
switch state {
case 0:
switch data[x] {
diff --git a/lib/spf/result.go b/lib/spf/result.go
index 5903a14a..43385d8d 100644
--- a/lib/spf/result.go
+++ b/lib/spf/result.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package spf
@@ -101,7 +101,7 @@ func (result *Result) lookup() {
var found int
- for x := 0; x < len(txts); x++ {
+ for x := range len(txts) {
rdata, ok := txts[x].Value.(string)
if !ok {
continue
diff --git a/lib/sshconfig/parser.go b/lib/sshconfig/parser.go
index 152b3fee..3c460a6f 100644
--- a/lib/sshconfig/parser.go
+++ b/lib/sshconfig/parser.go
@@ -1,6 +1,6 @@
-// Copyright 2020, 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: 2020 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package sshconfig
@@ -88,7 +88,7 @@ func (p *parser) load(dir, pattern string) (lines []string, err error) {
dir = filepath.Dir(pattern)
// Check and parse the Include directive in each lines.
- for x := 0; x < len(rawLines); x++ {
+ for x := range len(rawLines) {
if !isIncludeDirective(rawLines[x]) {
lines = append(lines, rawLines[x])
continue
@@ -200,7 +200,7 @@ func readLines(file string) (lines []string, err error) {
}
rawLines := bytes.Split(contents, []byte{'\n'})
- for x := 0; x < len(rawLines); x++ {
+ for x := range len(rawLines) {
rawLines[x] = bytes.TrimSpace(rawLines[x])
if len(rawLines[x]) == 0 {
continue
diff --git a/lib/sshconfig/section_match.go b/lib/sshconfig/section_match.go
index 4d9c7523..5baefc4d 100644
--- a/lib/sshconfig/section_match.go
+++ b/lib/sshconfig/section_match.go
@@ -1,6 +1,6 @@
-// Copyright 2020, 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: 2020 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package sshconfig
@@ -38,7 +38,8 @@ func newSectionMatch(cfg *Config, rawPattern string) (match *Section, err error)
isNegate bool
)
- for x := 0; x < len(args); x++ {
+ var x int
+ for ; x < len(args); x++ {
token := strings.ToLower(args[x])
if x+1 < len(args) {
arg = args[x+1]
diff --git a/lib/strings/parser_test.go b/lib/strings/parser_test.go
index adc4baa6..dca30c63 100644
--- a/lib/strings/parser_test.go
+++ b/lib/strings/parser_test.go
@@ -1,6 +1,6 @@
-// Copyright 2019, 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: 2019 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package strings
@@ -70,7 +70,7 @@ b`,
for _, c := range cases {
p.Load(c.content, "\n")
- for x := 0; x < len(c.exp); x++ {
+ for x := range len(c.exp) {
gotLine, gotC := p.Line()
test.Assert(t, ``, c.exp[x].line, gotLine)
test.Assert(t, ``, c.exp[x].c, gotC)
diff --git a/lib/strings/row.go b/lib/strings/row.go
index dd2b5598..d69139a7 100644
--- a/lib/strings/row.go
+++ b/lib/strings/row.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 strings
@@ -43,7 +43,7 @@ func (row Row) IsEqual(b Row) bool {
// Join list of slice of string using `lsep` as separator between row items
// and `ssep` for element in each item.
func (row Row) Join(lsep string, ssep string) (s string) {
- for x := 0; x < len(row); x++ {
+ for x := range len(row) {
if x > 0 {
s += lsep
}
diff --git a/lib/strings/strings.go b/lib/strings/strings.go
index dd20ba1e..1a2e2320 100644
--- a/lib/strings/strings.go
+++ b/lib/strings/strings.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 strings provide a library for working with string or slice of
// strings.
@@ -17,9 +17,9 @@ import (
func AppendUniq(in []string, vals ...string) []string {
var found bool
- for x := 0; x < len(vals); x++ {
+ for x := range len(vals) {
found = false
- for y := 0; y < len(in); y++ {
+ for y := range len(in) {
if vals[x] == in[y] {
found = true
break
@@ -53,7 +53,7 @@ func CountMissRate(src []string, target []string) (
length = targetlen
}
- for x := 0; x < length; x++ {
+ for x := range length {
if src[x] != target[x] {
nmiss++
}
@@ -91,7 +91,7 @@ func CountTokens(words []string, tokens []string, sensitive bool) []int {
counters := make([]int, tokenslen)
- for x := 0; x < len(tokens); x++ {
+ for x := range len(tokens) {
counters[x] = CountToken(words, tokens[x], sensitive)
}
@@ -143,7 +143,7 @@ func FrequencyOfTokens(words, tokens []string, sensitive bool) (probs []float64)
probs = make([]float64, len(tokens))
- for x := 0; x < len(tokens); x++ {
+ for x := range len(tokens) {
probs[x] = FrequencyOfToken(words, tokens[x], sensitive)
}
@@ -153,7 +153,7 @@ func FrequencyOfTokens(words, tokens []string, sensitive bool) (probs []float64)
// IsContain return true if elemen `el` is in slice of string `ss`,
// otherwise return false.
func IsContain(ss []string, el string) bool {
- for x := 0; x < len(ss); x++ {
+ for x := range len(ss) {
if ss[x] == el {
return true
}
@@ -202,7 +202,7 @@ func Longest(words []string) (string, int) {
outlen, idx int
out string
)
- for x := 0; x < len(words); x++ {
+ for x := range len(words) {
vlen := len(words[x])
if vlen > outlen {
outlen = vlen
@@ -237,7 +237,7 @@ func MostFrequentTokens(words []string, tokens []string, sensitive bool) string
func SortByIndex(ss *[]string, sortedListID []int) {
newd := make([]string, len(*ss))
- for x := 0; x < len(sortedListID); x++ {
+ for x := range len(sortedListID) {
newd[x] = (*ss)[sortedListID[x]]
}
@@ -269,7 +269,7 @@ func TotalFrequencyOfTokens(words, tokens []string, sensitive bool) float64 {
var sumfreq float64
- for x := 0; x < len(tokens); x++ {
+ for x := range len(tokens) {
sumfreq += FrequencyOfToken(words, tokens[x], sensitive)
}
@@ -283,7 +283,7 @@ func TotalFrequencyOfTokens(words, tokens []string, sensitive bool) float64 {
func Uniq(words []string, sensitive bool) (uniques []string) {
var xcmp, ycmp string
- for x := 0; x < len(words); x++ {
+ for x := range len(words) {
if len(words[x]) == 0 {
continue
}
diff --git a/lib/strings/table.go b/lib/strings/table.go
index 21e25e28..9e9f8d6f 100644
--- a/lib/strings/table.go
+++ b/lib/strings/table.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 strings
@@ -78,7 +78,7 @@ func SinglePartition(ss []string) Table {
table := make(Table, 0)
row := make(Row, len(ss))
- for x := 0; x < len(ss); x++ {
+ for x := range len(ss) {
row[x] = []string{ss[x]}
}
@@ -97,8 +97,8 @@ func (table Table) IsEqual(other Table) bool {
check := make([]bool, len(table))
- for x := 0; x < len(table); x++ {
- for y := 0; y < len(other); y++ {
+ for x := range len(table) {
+ for y := range len(other) {
if table[x].IsEqual(other[y]) {
check[x] = true
break
@@ -118,7 +118,7 @@ func (table Table) IsEqual(other Table) bool {
// different record in different new row.
func (table Table) JoinCombination(s string) (tout Table) {
for _, row := range table {
- for y := 0; y < len(row); y++ {
+ for y := range len(row) {
newRow := make(Row, len(row))
copy(newRow, row)
newRow[y] = append(newRow[y], s)
diff --git a/lib/strings/to.go b/lib/strings/to.go
index 6b46a724..0c00005b 100644
--- a/lib/strings/to.go
+++ b/lib/strings/to.go
@@ -12,7 +12,7 @@ import (
// ToBytes convert slice of string into slice of slice of bytes.
func ToBytes(ss []string) (sv [][]byte) {
- for x := 0; x < len(ss); x++ {
+ for x := range len(ss) {
sv = append(sv, []byte(ss[x]))
}
return sv
@@ -64,7 +64,7 @@ func ToInt64(ss []string) (sv []int64) {
// ToStrings convert slice of interface to slice of string.
func ToStrings(is []any) (vs []string) {
- for x := 0; x < len(is); x++ {
+ for x := range len(is) {
v := fmt.Sprintf("%v", is[x])
vs = append(vs, v)
}
diff --git a/lib/tabula/column.go b/lib/tabula/column.go
index d7d85483..b89acffc 100644
--- a/lib/tabula/column.go
+++ b/lib/tabula/column.go
@@ -55,7 +55,7 @@ func NewColumnString(data []string, colType int, colName string) (
col.Records = make([]*Record, datalen)
- for x := 0; x < datalen; x++ {
+ for x := range datalen {
col.Records[x] = NewRecordString(data[x])
}
@@ -92,7 +92,7 @@ func NewColumnReal(data []float64, colName string) (col *Column) {
col.Records = make([]*Record, datalen)
- for x := 0; x < datalen; x++ {
+ for x := range datalen {
rec := NewRecordReal(data[x])
col.Records[x] = rec
}
@@ -240,7 +240,7 @@ func (col *Column) SetValues(values []string) {
minlen = vallen
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
_ = col.Records[x].SetValue(values[x], col.Type)
}
}
diff --git a/lib/tabula/columns.go b/lib/tabula/columns.go
index 465cc828..6a79e341 100644
--- a/lib/tabula/columns.go
+++ b/lib/tabula/columns.go
@@ -1,6 +1,6 @@
-// Copyright 2017m 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: 2017 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package tabula
@@ -35,7 +35,7 @@ func (cols *Columns) SetTypes(types []int) {
minlen = colslen
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
(*cols)[x].Type = types[x]
}
}
diff --git a/lib/tabula/dataset.go b/lib/tabula/dataset.go
index e6e87b3b..3fee622b 100644
--- a/lib/tabula/dataset.go
+++ b/lib/tabula/dataset.go
@@ -218,7 +218,7 @@ func (dataset *Dataset) SetColumnsName(names []string) {
minlen = nameslen
}
- for x := 0; x < minlen; x++ {
+ for x := range minlen {
dataset.Columns[x].Name = names[x]
}
}
@@ -376,7 +376,7 @@ func (dataset *Dataset) TransposeToColumns() {
}
for _, row := range dataset.Rows {
- for y := 0; y < minlen; y++ {
+ for y := range minlen {
dataset.Columns[y].PushBack((*row)[y])
}
}
@@ -473,7 +473,7 @@ func (dataset *Dataset) PushRowToColumns(row *Row) {
min = collen
}
- for x := 0; x < min; x++ {
+ for x := range min {
dataset.Columns[x].PushBack((*row)[x])
}
}
@@ -608,7 +608,7 @@ func (dataset *Dataset) PushColumnToRows(col Column) {
var row *Row
var rec *Record
- for x := 0; x < minrow; x++ {
+ for x := range minrow {
row = dataset.Rows[x]
rec = col.Records[x]
diff --git a/lib/test/mock/rand_reader_example_test.go b/lib/test/mock/rand_reader_example_test.go
index 20e0adab..9e945a41 100644
--- a/lib/test/mock/rand_reader_example_test.go
+++ b/lib/test/mock/rand_reader_example_test.go
@@ -1,6 +1,6 @@
-// Copyright 2024, 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: 2024 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
package mock_test
@@ -18,14 +18,13 @@ func ExampleRandReader() {
rr = mock.NewRandReader(seed)
b = make([]byte, 8)
- x int
n int
err error
)
rand.Reader = rr
- for x = 0; x <= len(seed); x++ {
+ for range len(seed) + 1 {
n, err = rand.Read(b)
if err != nil {
log.Fatal(err)
diff --git a/lib/text/chunk.go b/lib/text/chunk.go
index 9211b15b..a904f2bd 100644
--- a/lib/text/chunk.go
+++ b/lib/text/chunk.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 text
@@ -22,7 +22,7 @@ type Chunk struct {
func JoinChunks(chunks []Chunk, sep string) string {
var out string
- for x := 0; x < len(chunks); x++ {
+ for x := range len(chunks) {
if x > 0 {
out += sep
}
diff --git a/lib/totp/totp.go b/lib/totp/totp.go
index c1d14832..f3cc5168 100644
--- a/lib/totp/totp.go
+++ b/lib/totp/totp.go
@@ -1,3 +1,7 @@
+// SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info>
+//
+// SPDX-License-Identifier: BSD-3-Clause
+
// Package totp implement Time-Based One-Time Password Algorithm based on RFC
// 6238 [1].
//
@@ -128,7 +132,7 @@ func (p *Protocol) generateN(mac hash.Hash, ts int64, n int) (listOTP []string,
t int64
x int
)
- for x = 0; x < n; x++ {
+ for x = range n {
t = ts - int64(x*p.timeStep)
otp, err = p.generateWithTimestamp(mac, t)
if err != nil {
@@ -170,7 +174,7 @@ func (p *Protocol) verifyWithTimestamp(mac hash.Hash, token string, steps int, t
x int
)
- for x = 0; x < steps; x++ {
+ for x = range steps {
t = ts - int64(x*p.timeStep)
otp, err = p.generateWithTimestamp(mac, t)
if err != nil {
diff --git a/lib/websocket/client_test.go b/lib/websocket/client_test.go
index 091b1aa5..827b3d9c 100644
--- a/lib/websocket/client_test.go
+++ b/lib/websocket/client_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 websocket
@@ -541,7 +541,7 @@ func TestClientFragmentation2(t *testing.T) {
payload: []byte("Shulhan"),
}}
- for x = 0; x < len(frames); x++ {
+ for x = range len(frames) {
req = frames[x].pack()
testClient.Lock()
diff --git a/lib/websocket/frame.go b/lib/websocket/frame.go
index b3003aaa..235f166b 100644
--- a/lib/websocket/frame.go
+++ b/lib/websocket/frame.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 websocket
@@ -296,7 +296,7 @@ func (f *Frame) pack() (out []byte) {
out[x] = f.maskKey[3]
x++
- for y = 0; y < payloadSize; y++ {
+ for y = range payloadSize {
out[x] = f.payload[y] ^ f.maskKey[y%4]
x++
}
diff --git a/lib/websocket/websocket_test.go b/lib/websocket/websocket_test.go
index ed205692..ee58956a 100644
--- a/lib/websocket/websocket_test.go
+++ b/lib/websocket/websocket_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 websocket
@@ -42,7 +42,7 @@ func generateDummyPayload(size uint64) (payload []byte, masked []byte) {
copy(payload[x:], payload[:x])
}
- for x = 0; x < size; x++ {
+ for x = range size {
masked[x] = payload[x] ^ _testMaskKey[x%4]
}
diff --git a/lib/xmlrpc/value.go b/lib/xmlrpc/value.go
index 00d6f010..13537c75 100644
--- a/lib/xmlrpc/value.go
+++ b/lib/xmlrpc/value.go
@@ -79,7 +79,7 @@ func NewValue(in any) (out *Value) {
case reflect.Struct:
out.Kind = Struct
out.StructMembers = make(map[string]*Value, reft.NumField())
- for x := 0; x < reft.NumField(); x++ {
+ for x := range reft.NumField() {
var name string
field := reft.Field(x)
@@ -98,7 +98,7 @@ func NewValue(in any) (out *Value) {
case reflect.Array, reflect.Slice:
out.Kind = Array
- for x := 0; x < refv.Len(); x++ {
+ for x := range refv.Len() {
v := NewValue(refv.Index(x).Interface())
if v != nil {
out.ArrayValues = append(out.ArrayValues, v)