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

all: simplify return if ... constructs to make more code compatible with -autofree

This commit is contained in:
Delyan Angelov
2021-03-22 16:45:29 +02:00
parent a53aaaf9e7
commit c76c69ec35
9 changed files with 129 additions and 71 deletions

View File

@ -982,10 +982,15 @@ pub fn (s string) capitalize() string {
if s.len == 0 {
return ''
}
return s[0].ascii_str().to_upper() + s[1..]
// sl := s.to_lower()
// cap := sl[0].str().to_upper() + sl[1..]
// return cap
s0 := s[0]
letter := s0.ascii_str()
uletter := letter.to_upper()
if s.len == 1 {
return uletter
}
srest := s[1..]
res := uletter + srest
return res
}
// is_capital returns `true` if the first character in the string is a capital letter.
@ -1042,16 +1047,6 @@ pub fn (s string) find_between(start string, end string) string {
return val[..end_pos]
}
/*
pub fn (a []string) to_c() voidptr {
mut res := malloc(sizeof(byteptr) * a.len)
for i in 0..a.len {
val := a[i]
res[i] = val.str
}
return res
}
*/
// is_space returns `true` if the byte is a white space character.
// The following list is considered white space characters: ` `, `\n`, `\t`, `\v`, `\f`, `\r`, 0x85, 0xa0
// Example: assert byte(` `).is_space() == true
@ -1141,7 +1136,10 @@ pub fn (s string) trim_right(cutset string) string {
}
pos--
}
return if pos < 0 { '' } else { s[..pos + 1] }
if pos < 0 {
return ''
}
return s[..pos + 1]
}
// trim_prefix strips `str` from the start of the string.