mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
string: fix contains behaviour (closes #5371)
This commit is contained in:
parent
7e0197c1b8
commit
2ef0f15b34
@ -716,6 +716,9 @@ pub fn (s string) count(substr string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn (s string) contains(p string) bool {
|
pub fn (s string) contains(p string) bool {
|
||||||
|
if p.len == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
s.index(p) or {
|
s.index(p) or {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -357,6 +357,8 @@ fn test_contains() {
|
|||||||
s := 'view.v'
|
s := 'view.v'
|
||||||
assert s.contains('vi')
|
assert s.contains('vi')
|
||||||
assert !s.contains('random')
|
assert !s.contains('random')
|
||||||
|
assert ''.contains('')
|
||||||
|
assert 'abc'.contains('')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_arr_contains() {
|
fn test_arr_contains() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user