Skip to content

Commit

Permalink
builtin: fix the string.index_any method (#11310)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lathanao committed Sep 6, 2021
1 parent 6084c0f commit 78c26e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions vlib/builtin/string.v
Expand Up @@ -739,12 +739,12 @@ fn (s string) index_kmp(p string) int {

// index_any returns the position of any of the characters in the input string - if found.
pub fn (s string) index_any(chars string) int {
for c in chars {
idx := s.index_(c.ascii_str())
if idx == -1 {
continue
for i, ss in s {
for c in chars {
if c == ss {
return i
}
}
return idx
}
return -1
}
Expand Down
6 changes: 6 additions & 0 deletions vlib/builtin/string_test.v
Expand Up @@ -910,3 +910,9 @@ fn test_string_to_rune() {
x := 'Hello World 👋'
assert x.runes().len == 13
}

fn test_index_any() {
x := 'abcdefghij'
assert x.index_any('ef') == 4
assert x.index_any('fe') == 4
}

0 comments on commit 78c26e6

Please sign in to comment.