Skip to content

Commit 1475b43

Browse files
committed
👔 up: strutil - add new func: ContainsByteOne
1 parent 53c0997 commit 1475b43

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

fsutil/info.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ func PathNoExt(fPath string) string {
3030

3131
// Name get file/dir name from full path.
3232
//
33-
// eg: path/to/main.go => "main.go"
33+
// eg:
34+
// "path/to/main.go" => "main.go"
35+
// "/foo/bar/baz" => "baz"
3436
func Name(fPath string) string {
3537
if fPath == "" {
3638
return ""

strutil/check.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ func IContains(s, sub string) bool {
116116
// ContainsByte in given string.
117117
func ContainsByte(s string, c byte) bool { return strings.IndexByte(s, c) >= 0 }
118118

119+
// ContainsByteOne in given string.
120+
func ContainsByteOne(s string, bs []byte) bool {
121+
for _, b := range bs {
122+
if strings.IndexByte(s, b) >= 0 {
123+
return true
124+
}
125+
}
126+
return false
127+
}
128+
119129
// InArray alias of HasOneSub()
120130
var InArray = HasOneSub
121131

strutil/check_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ func TestIContains(t *testing.T) {
233233

234234
assert.True(t, strutil.ContainsByte("H3AB2C", 'A'))
235235
assert.False(t, strutil.ContainsByte("H3AB2C", 'a'))
236+
237+
assert.True(t, strutil.ContainsByteOne("H3AB2C", []byte("A")))
238+
assert.True(t, strutil.ContainsByteOne("H3AB2C", []byte("DB")))
239+
assert.False(t, strutil.ContainsByteOne("H3AB2C", []byte("D")))
236240
}
237241

238242
func TestHasOneSub(t *testing.T) {

0 commit comments

Comments
 (0)