diff --git a/vlib/builtin/js/byte.js.v b/vlib/builtin/js/byte.js.v index 5dfcc50f9c..9ba4e6cf05 100644 --- a/vlib/builtin/js/byte.js.v +++ b/vlib/builtin/js/byte.js.v @@ -39,7 +39,7 @@ pub fn (c u8) is_digit() bool { // Example: assert u8(`F`) == true @[inline] pub fn (c u8) is_hex_digit() bool { - return (c >= `0` && c <= `9`) || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`) + return c.is_digit() || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`) } // is_oct_digit returns `true` if the byte is in range 0-7 and `false` otherwise. diff --git a/vlib/builtin/js/string.js.v b/vlib/builtin/js/string.js.v index e6d09a5565..983361bb09 100644 --- a/vlib/builtin/js/string.js.v +++ b/vlib/builtin/js/string.js.v @@ -952,7 +952,7 @@ pub fn (s string) is_capital() bool { // Example: assert 'Hello. World.'.starts_with_capital() == true @[direct_array_access] pub fn (s string) starts_with_capital() bool { - if s.len == 0 || !(s[0] >= `A` && s[0] <= `Z`) { + if s.len == 0 || !s[0].is_capital() { return false } return true diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 4dcb9f6ac9..6cf1b50e1f 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -1518,7 +1518,7 @@ pub fn (s string) to_lower() string { unsafe { mut b := malloc_noscan(s.len + 1) for i in 0 .. s.len { - if s.str[i] >= `A` && s.str[i] <= `Z` { + if s.str[i].is_capital() { b[i] = s.str[i] + 32 } else { b[i] = s.str[i] @@ -1637,7 +1637,7 @@ pub fn (s string) is_capital() bool { // Example: assert 'Hello. World.'.starts_with_capital() == true @[direct_array_access] pub fn (s string) starts_with_capital() bool { - if s.len == 0 || !(s[0] >= `A` && s[0] <= `Z`) { + if s.len == 0 || !s[0].is_capital() { return false } return true @@ -2043,7 +2043,7 @@ pub fn (c u8) is_digit() bool { // Example: assert u8(`F`).is_hex_digit() == true @[inline] pub fn (c u8) is_hex_digit() bool { - return (c >= `0` && c <= `9`) || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`) + return c.is_digit() || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`) } // is_oct_digit returns `true` if the byte is in range 0-7 and `false` otherwise. @@ -2652,9 +2652,9 @@ pub fn (s string) camel_to_snake() string { } mut b := unsafe { malloc_noscan(2 * s.len + 1) } mut prev_is_upper := false - first_char, second_char := if s[0] >= `A` && s[0] <= `Z` { - lower_first_c := if s[0] >= `A` && s[0] <= `Z` { s[0] + 32 } else { s[0] } - lower_second_c := if s[1] >= `A` && s[1] <= `Z` { + first_char, second_char := if s[0].is_capital() { + lower_first_c := s[0] + 32 + lower_second_c := if s[1].is_capital() { prev_is_upper = true s[1] + 32 } else { @@ -2663,7 +2663,7 @@ pub fn (s string) camel_to_snake() string { lower_first_c, lower_second_c } else { lower_first_c := s[0] - second_c := if s[1] >= `A` && s[1] <= `Z` { u8(`_`) } else { s[1] } + second_c := if s[1].is_capital() { u8(`_`) } else { s[1] } lower_first_c, second_c } unsafe { @@ -2676,7 +2676,7 @@ pub fn (s string) camel_to_snake() string { mut c_is_upper := false for i in pos .. s.len { c := s[i] - c_is_upper = c >= `A` && c <= `Z` + c_is_upper = c.is_capital() lower_c = if c_is_upper { c + 32 } else { c } if !prev_is_upper && c_is_upper { // aB => a_b, if prev has `_`, then do not add `_` diff --git a/vlib/net/http/cookie.v b/vlib/net/http/cookie.v index ef49a251c2..ed4328ef04 100644 --- a/vlib/net/http/cookie.v +++ b/vlib/net/http/cookie.v @@ -248,7 +248,7 @@ pub fn is_cookie_domain_name(_s string) bool { mut part_len := 0 for i, _ in s { c := s[i] - if (`a` <= c && c <= `z`) || (`A` <= c && c <= `Z`) { + if c.is_letter() { // No '_' allowed here (in contrast to package net). ok = true part_len++ diff --git a/vlib/net/urllib/urllib.v b/vlib/net/urllib/urllib.v index 94927d9024..4ed8bb6b25 100644 --- a/vlib/net/urllib/urllib.v +++ b/vlib/net/urllib/urllib.v @@ -38,7 +38,7 @@ fn error_msg(message string, val string) string { // reserved characters correctly. See golang.org/issue/5684. fn should_escape(c u8, mode EncodingMode) bool { // ยง2.3 Unreserved characters (alphanum) - if (`a` <= c && c <= `z`) || (`A` <= c && c <= `Z`) || (`0` <= c && c <= `9`) { + if c.is_alnum() { return false } if mode == .encode_host || mode == .encode_zone { @@ -388,9 +388,9 @@ fn (u &Userinfo) str() string { fn split_by_scheme(rawurl string) ![]string { for i in 0 .. rawurl.len { c := rawurl[i] - if (`a` <= c && c <= `z`) || (`A` <= c && c <= `Z`) { + if c.is_letter() { // do nothing - } else if (`0` <= c && c <= `9`) || (c == `+` || c == `-` || c == `.`) { + } else if c.is_digit() || c in [`+`, `-`, `.`] { if i == 0 { return ['', rawurl] } @@ -1016,13 +1016,7 @@ pub fn split_host_port(hostport string) (string, string) { // It doesn't validate pct-encoded. The caller does that via fn unescape. pub fn valid_userinfo(s string) bool { for r in s { - if `A` <= r && r <= `Z` { - continue - } - if `a` <= r && r <= `z` { - continue - } - if `0` <= r && r <= `9` { + if r.is_alnum() { continue } match r { diff --git a/vlib/strings/strings.v b/vlib/strings/strings.v index df08a26dbe..4f18e22fa8 100644 --- a/vlib/strings/strings.v +++ b/vlib/strings/strings.v @@ -134,7 +134,7 @@ pub fn split_capital(s string) []string { mut res := []string{} mut word_start := 0 for idx, c in s { - if c >= `A` && c <= `Z` { + if c.is_capital() { if word_start != idx { res << s#[word_start..idx] } diff --git a/vlib/toml/util/util.v b/vlib/toml/util/util.v index a4a9e24d4d..479c84b159 100644 --- a/vlib/toml/util/util.v +++ b/vlib/toml/util/util.v @@ -6,7 +6,7 @@ module util // is_key_char returns true if the given u8 is a valid key character. @[inline] pub fn is_key_char(c u8) bool { - return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) // || c == `_` || c == `-` <- these are identified when tokenizing + return c.is_letter() // || c == `_` || c == `-` <- these are identified when tokenizing } // is_ascii_control_character returns true if `byte_char` is an ASCII control character. diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index ec0f2eda2f..ec56a76e7b 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -239,7 +239,7 @@ fn (mut s Scanner) ident_name() string { s.pos++ for s.pos < s.text.len { c := s.text[s.pos] - if (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`) || c == `_` { + if c.is_alnum() || c == `_` { s.pos++ continue } diff --git a/vlib/v/util/scanning.v b/vlib/v/util/scanning.v index cb312d8f3c..e6eeac7c68 100644 --- a/vlib/v/util/scanning.v +++ b/vlib/v/util/scanning.v @@ -2,17 +2,17 @@ module util @[inline] pub fn is_name_char(c u8) bool { - return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || c == `_` + return c.is_letter() || c == `_` } @[inline] pub fn is_func_char(c u8) bool { - return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || c == `_` || (c >= `0` && c <= `9`) + return c.is_letter() || c == `_` || c.is_digit() } pub fn contains_capital(s string) bool { for c in s { - if c >= `A` && c <= `Z` { + if c.is_capital() { return true } } diff --git a/vlib/v2/scanner/scanner.v b/vlib/v2/scanner/scanner.v index 9177b9a502..bd20b22c8e 100644 --- a/vlib/v2/scanner/scanner.v +++ b/vlib/v2/scanner/scanner.v @@ -131,8 +131,7 @@ pub fn (mut s Scanner) scan() token.Token { } for s.offset < s.src.len { c3 := s.src[s.offset] - if (c3 >= `a` && c3 <= `z`) || (c3 >= `A` && c3 <= `Z`) - || (c3 >= `0` && c3 <= `9`) || c3 == `_` { + if c3.is_alnum() || c3 == `_` { s.offset++ continue }