builtin: add string.trim_indexes method, that can be used in string.trim, but also separately from it (#16144)

This commit is contained in:
l-m 2022-10-22 20:56:05 +11:00 committed by GitHub
parent b6faf82911
commit a139bed785
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View file

@ -538,6 +538,16 @@ fn test_trim() {
assert 'aaabccc'.trim('ac') == 'b'
}
fn test_trim_indexes() {
mut left, mut right := 0, 0
left, right = '- -- - '.trim_indexes(' -')
assert left == 0 && right == 0
left, right = '- hello-world!\t'.trim_indexes(' -\t')
assert left == 2 && right == 14
left, right = 'abc'.trim_indexes('ac')
assert left == 1 && right == 2
}
fn test_trim_left() {
mut s := 'module main'
assert s.trim_left(' ') == 'module main'