From dd2490ca26d620de0d5cbddc99d22bccd73e3d2c Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 13 Sep 2023 21:41:44 +0200 Subject: twtstr: simplify * remove unused function isAlphaAscii * swap pushHex for less casting * remove == overload for char/rune (we did not really use it anyway) --- src/css/mediaquery.nim | 5 +++-- src/utils/twtstr.nim | 16 +++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) (limited to 'src') 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)) -- cgit 1.4.1-2-gfad0