mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
fix: disable specific staticcheck rules and update lint config - Disabled staticcheck rules SA1029, SA1019, S1000, and related checks in `.golangci.yml` to filter out unwanted linter errors. - Updated staticcheck checks list for more precise linting control. - Clarified configuration for easier maintenance and future updates. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: hailaz <739476267@qq.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gstr
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// Count counts the number of `substr` appears in `s`.
|
|
// It returns 0 if no `substr` found in `s`.
|
|
func Count(s, substr string) int {
|
|
return strings.Count(s, substr)
|
|
}
|
|
|
|
// CountI counts the number of `substr` appears in `s`, case-insensitively.
|
|
// It returns 0 if no `substr` found in `s`.
|
|
func CountI(s, substr string) int {
|
|
return strings.Count(ToLower(s), ToLower(substr))
|
|
}
|
|
|
|
// CountWords returns information about words' count used in a string.
|
|
// It considers parameter `str` as unicode string.
|
|
func CountWords(str string) map[string]int {
|
|
m := make(map[string]int)
|
|
buffer := bytes.NewBuffer(nil)
|
|
for _, r := range str {
|
|
if unicode.IsSpace(r) {
|
|
if buffer.Len() > 0 {
|
|
m[buffer.String()]++
|
|
buffer.Reset()
|
|
}
|
|
} else {
|
|
buffer.WriteRune(r)
|
|
}
|
|
}
|
|
if buffer.Len() > 0 {
|
|
m[buffer.String()]++
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CountChars returns information about chars' count used in a string.
|
|
// It considers parameter `str` as Unicode string.
|
|
func CountChars(str string, noSpace ...bool) map[string]int {
|
|
m := make(map[string]int)
|
|
countSpace := len(noSpace) == 0 || !noSpace[0]
|
|
for _, r := range str {
|
|
if !countSpace && unicode.IsSpace(r) {
|
|
continue
|
|
}
|
|
m[string(r)]++
|
|
}
|
|
return m
|
|
}
|