about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-07-07 19:12:31 +0200
committerbptato <nincsnevem662@gmail.com>2023-07-07 19:12:31 +0200
commit45f58316b4da12e893856e47a4296ee09c49449e (patch)
tree20ae54604051d9a7c2250b24cf6df9a802214a55 /src/utils/twtstr.nim
parentda3c7385d1e19ba97aee0b6220d26994eef985e8 (diff)
downloadchawan-45f58316b4da12e893856e47a4296ee09c49449e.tar.gz
Fix toHex weirdness
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index a32cc8da..df67b8f3 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -174,10 +174,9 @@ func isAscii*(s: string): bool =
 
 const HexCharsUpper = "0123456789ABCDEF"
 const HexCharsLower = "0123456789abcdef"
-func toHex*(c: char): string =
-  result = newString(2)
-  result[0] = HexCharsUpper[(uint8(c) shr 4)]
-  result[1] = HexCharsLower[(uint8(c) and 0xF)]
+func pushHex*(buf: var string, c: char) =
+  buf &= HexCharsUpper[(uint8(c) shr 4)]
+  buf &= HexCharsUpper[(uint8(c) and 0xF)]
 
 func toHexLower*(u: uint16): string =
   var x = u
@@ -195,8 +194,8 @@ func toHexLower*(u: uint16): string =
     x = x shr 4
   return s
 
-func toHex*(i: uint8): string =
-  return toHex(cast[char](i))
+func pushHex*(buf: var string, i: uint8) =
+  buf.pushHex(cast[char](i))
 
 func equalsIgnoreCase*(s1: seq[Rune], s2: string): bool =
   var i = 0
@@ -558,7 +557,7 @@ proc percentEncode*(append: var string, c: char, set: set[char], spaceAsPlus = f
     append &= c
   else:
     append &= '%'
-    append &= c.toHex()
+    append.pushHex(c)
 
 proc percentEncode*(append: var string, s: string, set: set[char], spaceAsPlus = false) {.inline.} =
   for c in s: