builtin: fix the string.index_any method (#11310)
parent
6084c0fc54
commit
78c26e69cf
|
@ -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.
|
// 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 {
|
pub fn (s string) index_any(chars string) int {
|
||||||
for c in chars {
|
for i, ss in s {
|
||||||
idx := s.index_(c.ascii_str())
|
for c in chars {
|
||||||
if idx == -1 {
|
if c == ss {
|
||||||
continue
|
return i
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return idx
|
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
|
@ -910,3 +910,9 @@ fn test_string_to_rune() {
|
||||||
x := 'Hello World 👋'
|
x := 'Hello World 👋'
|
||||||
assert x.runes().len == 13
|
assert x.runes().len == 13
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_index_any() {
|
||||||
|
x := 'abcdefghij'
|
||||||
|
assert x.index_any('ef') == 4
|
||||||
|
assert x.index_any('fe') == 4
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue