mirror of
https://github.com/vlang/v.git
synced 2025-08-04 10:17:22 -04:00
builtin.string: fix is_upper
and is_lower
with numbers (#21357)
This commit is contained in:
parent
6c113cf777
commit
c7af2c21d1
@ -1524,6 +1524,9 @@ pub fn (s string) to_lower() string {
|
|||||||
// Example: assert 'hello developer'.is_lower() == true
|
// Example: assert 'hello developer'.is_lower() == true
|
||||||
@[direct_array_access]
|
@[direct_array_access]
|
||||||
pub fn (s string) is_lower() bool {
|
pub fn (s string) is_lower() bool {
|
||||||
|
if s[0].is_digit() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
for i in 0 .. s.len {
|
for i in 0 .. s.len {
|
||||||
if s[i] >= `A` && s[i] <= `Z` {
|
if s[i] >= `A` && s[i] <= `Z` {
|
||||||
return false
|
return false
|
||||||
@ -1555,6 +1558,9 @@ pub fn (s string) to_upper() string {
|
|||||||
// Example: assert 'HELLO V'.is_upper() == true
|
// Example: assert 'HELLO V'.is_upper() == true
|
||||||
@[direct_array_access]
|
@[direct_array_access]
|
||||||
pub fn (s string) is_upper() bool {
|
pub fn (s string) is_upper() bool {
|
||||||
|
if s[0].is_digit() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
for i in 0 .. s.len {
|
for i in 0 .. s.len {
|
||||||
if s[i] >= `a` && s[i] <= `z` {
|
if s[i] >= `a` && s[i] <= `z` {
|
||||||
return false
|
return false
|
||||||
|
@ -1013,6 +1013,9 @@ fn test_lower() {
|
|||||||
assert s.to_lower() == 'hi'
|
assert s.to_lower() == 'hi'
|
||||||
assert 'aloha!'[0] == `a`
|
assert 'aloha!'[0] == `a`
|
||||||
assert 'aloha!'[5] == `!`
|
assert 'aloha!'[5] == `!`
|
||||||
|
s = '123'
|
||||||
|
assert !s.is_lower()
|
||||||
|
assert s.to_lower() == '123'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_upper() {
|
fn test_upper() {
|
||||||
@ -1033,6 +1036,9 @@ fn test_upper() {
|
|||||||
s = 'HI'
|
s = 'HI'
|
||||||
assert s.is_upper()
|
assert s.is_upper()
|
||||||
assert s.to_upper() == 'HI'
|
assert s.to_upper() == 'HI'
|
||||||
|
s = '123'
|
||||||
|
assert !s.is_upper()
|
||||||
|
assert s.to_upper() == '123'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_capitalize() {
|
fn test_capitalize() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user