string: avoid double allocation in trim_space()
parent
dd070e616d
commit
5375038d88
|
@ -545,13 +545,12 @@ pub fn (s string) trim_space() string {
|
||||||
for i < s.len && is_space(s[i]) {
|
for i < s.len && is_space(s[i]) {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
mut res := s.right(i)
|
mut end := s.len - 1
|
||||||
mut end := res.len - 1
|
for end >= 0 && is_space(s[end]) {
|
||||||
for end >= 0 && is_space(res[end]) {
|
|
||||||
// C.printf('end=%d c=%d %c\n', end, res.str[end])
|
// C.printf('end=%d c=%d %c\n', end, res.str[end])
|
||||||
end--
|
end--
|
||||||
}
|
}
|
||||||
res = res.left(end + 1)
|
res := s.substr(i, end + 1)
|
||||||
// println('after SPACE "$res"')
|
// println('after SPACE "$res"')
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue