string: avoid double allocation in trim_space()

pull/1275/head
Rendims 2019-07-22 21:35:01 +02:00 committed by Alexander Medvednikov
parent dd070e616d
commit 5375038d88
1 changed files with 3 additions and 4 deletions

View File

@ -545,13 +545,12 @@ pub fn (s string) trim_space() string {
for i < s.len && is_space(s[i]) {
i++
}
mut res := s.right(i)
mut end := res.len - 1
for end >= 0 && is_space(res[end]) {
mut end := s.len - 1
for end >= 0 && is_space(s[end]) {
// C.printf('end=%d c=%d %c\n', end, res.str[end])
end--
}
res = res.left(end + 1)
res := s.substr(i, end + 1)
// println('after SPACE "$res"')
return res
}