aboutsummaryrefslogtreecommitdiff
path: root/lib/strings
diff options
context:
space:
mode:
Diffstat (limited to 'lib/strings')
-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
5 files changed, 30 insertions, 30 deletions
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)
}