string.reverse() (#641)

pull/691/head
Robin Martijn 2019-06-27 02:03:19 +02:00 committed by Alexander Medvednikov
parent 8b3802d9b8
commit a409a60b11
1 changed files with 13 additions and 0 deletions

View File

@ -771,6 +771,19 @@ fn (s[]string) join_lines() string {
return s.join('\n') return s.join('\n')
} }
fn (s string) reverse() string {
mut res := string {
len: s.len
str: malloc(s.len + 1)
}
for i := s.len - 1; i >= 0; i-- {
res[s.len-i-1] = s[i]
}
return res
}
// 'hello'.limit(2) => 'he' // 'hello'.limit(2) => 'he'
// 'hi'.limit(10) => 'hi' // 'hi'.limit(10) => 'hi'
fn (s string) limit(max int) string { fn (s string) limit(max int) string {