1
0
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:
yuyi 2020-06-14 17:24:15 +08:00 committed by GitHub
parent 7e0197c1b8
commit 2ef0f15b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -716,6 +716,9 @@ pub fn (s string) count(substr string) int {
}
pub fn (s string) contains(p string) bool {
if p.len == 0 {
return true
}
s.index(p) or {
return false
}

View File

@ -357,6 +357,8 @@ fn test_contains() {
s := 'view.v'
assert s.contains('vi')
assert !s.contains('random')
assert ''.contains('')
assert 'abc'.contains('')
}
fn test_arr_contains() {