mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
string: add is_upper/is_lower and fix parser.match_expr error
* string: add is_upper/is_lower and fix parser.match_expr error * to_capital => capitalize, to_title => title * is_titled => is_title, is_capitalized => is_capital
This commit is contained in:
@ -744,6 +744,15 @@ pub fn (s string) to_lower() string {
|
||||
return tos(b, s.len)
|
||||
}
|
||||
|
||||
pub fn (s string) is_lower() bool {
|
||||
for i in 0..s.len {
|
||||
if s[i] >= `A` && s[i] <= `Z` {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
pub fn (s string) to_upper() string {
|
||||
mut b := malloc(s.len + 1)
|
||||
for i in 0..s.len {
|
||||
@ -752,6 +761,15 @@ pub fn (s string) to_upper() string {
|
||||
return tos(b, s.len)
|
||||
}
|
||||
|
||||
pub fn (s string) is_upper() bool {
|
||||
for i in 0..s.len {
|
||||
if s[i] >= `a` && s[i] <= `z` {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
pub fn (s string) capitalize() string {
|
||||
if s.len == 0 {
|
||||
return ''
|
||||
@ -761,6 +779,18 @@ pub fn (s string) capitalize() string {
|
||||
return cap
|
||||
}
|
||||
|
||||
pub fn (s string) is_capital() bool {
|
||||
if s.len == 0 || !(s[0] >= `A` && s[0] <= `Z`) {
|
||||
return false
|
||||
}
|
||||
for i in 1..s.len {
|
||||
if s[i] >= `A` && s[i] <= `Z` {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
pub fn (s string) title() string {
|
||||
words := s.split(' ')
|
||||
mut tit := []string
|
||||
@ -771,6 +801,16 @@ pub fn (s string) title() string {
|
||||
return title
|
||||
}
|
||||
|
||||
pub fn (s string) is_title() bool {
|
||||
words := s.split(' ')
|
||||
for word in words {
|
||||
if !word.is_capital() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 'hey [man] how you doin'
|
||||
// find_between('[', ']') == 'man'
|
||||
pub fn (s string) find_between(start, end string) string {
|
||||
|
Reference in New Issue
Block a user