1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

string.reverse() (#641)

This commit is contained in:
Robin Martijn 2019-06-27 02:03:19 +02:00 committed by Alexander Medvednikov
parent 8b3802d9b8
commit a409a60b11

View File

@ -771,6 +771,19 @@ fn (s[]string) join_lines() string {
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'
// 'hi'.limit(10) => 'hi'
fn (s string) limit(max int) string {