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

string: fix capitalize

This commit is contained in:
yuyi 2020-02-20 18:33:38 +08:00 committed by GitHub
parent d51019dd77
commit 8be07194c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -752,6 +752,9 @@ pub fn (s string) to_upper() string {
}
pub fn (s string) capitalize() string {
if s.len == 0 {
return ''
}
sl := s.to_lower()
cap := sl[0].str().to_upper() + sl.right(1)
return cap

View File

@ -503,6 +503,8 @@ fn test_capitalize() {
assert s.capitalize() == 'Test'
s = 'i am ray'
assert s.capitalize() == 'I am ray'
s = ''
assert s.capitalize() == ''
}
fn test_title() {