aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-13 21:41:44 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-13 21:45:23 +0200
commitdd2490ca26d620de0d5cbddc99d22bccd73e3d2c (patch)
tree7944158d60e42b905a9f8ce3b102e838c3277105
parent8271d05a889ad0ca35148847d06e6503ad5c121b (diff)
downloadchawan-dd2490ca26d620de0d5cbddc99d22bccd73e3d2c.tar.gz
twtstr: simplify
* remove unused function isAlphaAscii * swap pushHex for less casting * remove == overload for char/rune (we did not really use it anyway)
-rw-r--r--src/css/mediaquery.nim5
-rw-r--r--src/utils/twtstr.nim16
2 files changed, 8 insertions, 13 deletions
diff --git a/src/css/mediaquery.nim b/src/css/mediaquery.nim
index e59f1f80..c47dd911 100644
--- a/src/css/mediaquery.nim
+++ b/src/css/mediaquery.nim
@@ -1,5 +1,6 @@
import strutils
import tables
+import unicode
import css/cssparser
import css/values
@@ -197,7 +198,7 @@ template expect_comparison(comparison: var MediaQueryComparison) =
of '<':
if parser.has():
let tok = skip_consume()
- if tok == CSS_DELIM_TOKEN and tok.rvalue == '=':
+ if tok == CSS_DELIM_TOKEN and tok.rvalue == Rune('='):
comparison = COMPARISON_LE
break parse
parser.reconsume()
@@ -205,7 +206,7 @@ template expect_comparison(comparison: var MediaQueryComparison) =
of '>':
if parser.has():
let tok = skip_consume()
- if tok == CSS_DELIM_TOKEN and tok.rvalue == '=':
+ if tok == CSS_DELIM_TOKEN and tok.rvalue == Rune('='):
comparison = COMPARISON_GE
break parse
parser.reconsume()
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index d7b8139a..e2f2ee6c 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -117,9 +117,6 @@ func normalizeLocale*(s: string): string =
func isAscii*(r: Rune): bool =
return cast[uint32](r) < 128
-func `==`*(r: Rune, c: char): bool {.inline.} =
- return Rune(c) == r
-
func startsWithNoCase*(str, prefix: string): bool =
if str.len < prefix.len: return false
# prefix.len is always lower
@@ -159,9 +156,12 @@ func isAscii*(s: string): bool =
const HexCharsUpper = "0123456789ABCDEF"
const HexCharsLower = "0123456789abcdef"
+func pushHex*(buf: var string, u: uint8) =
+ buf &= HexCharsUpper[u shr 4]
+ buf &= HexCharsUpper[u and 0xF]
+
func pushHex*(buf: var string, c: char) =
- buf &= HexCharsUpper[(uint8(c) shr 4)]
- buf &= HexCharsUpper[(uint8(c) and 0xF)]
+ buf.pushHex(cast[uint8](c))
func toHexLower*(u: uint16): string =
var x = u
@@ -179,15 +179,9 @@ func toHexLower*(u: uint16): string =
x = x shr 4
return s
-func pushHex*(buf: var string, i: uint8) =
- buf.pushHex(cast[char](i))
-
func equalsIgnoreCase*(s1, s2: string): bool {.inline.} =
return s1.cmpIgnoreCase(s2) == 0
-func isAlphaAscii*(r: Rune): bool =
- return int(r) < 256 and isAlphaAscii(char(r))
-
func isDigitAscii*(r: Rune): bool =
return int(r) < 256 and isDigit(char(r))