summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-11-02 14:48:36 +0100
committerGitHub <noreply@github.com>2020-11-02 14:48:36 +0100
commit235e4930ab2f5a9a4c94d6cc66d62701ee58550d (patch)
treed51d1f29a10aae8531a56582d978ea50c68e48e9
parentdfd8a83f3557164fd41714c11c6f92b65eef9018 (diff)
downloadNim-235e4930ab2f5a9a4c94d6cc66d62701ee58550d.tar.gz
simplify toHex (#15821)
-rw-r--r--lib/pure/strutils.nim31
1 files changed, 2 insertions, 29 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index 740a6e391..491760137 100644
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -951,11 +951,11 @@ proc toHexImpl(x: BiggestUInt, len: Positive, handleNegative: bool): string {.no
     # handle negative overflow
     if n == 0 and handleNegative: n = not(BiggestUInt 0)
 
-proc toHex*(x: BiggestUInt, len: Positive): string {.noSideEffect.} =
+proc toHex*[T: SomeInteger](x: T, len: Positive): string {.noSideEffect.} =
   ## Converts `x` to its hexadecimal representation.
   ##
   ## The resulting string will be exactly `len` characters long. No prefix like
-  ## ``0x`` is generated.
+  ## ``0x`` is generated. `x` is treated as an unsigned value.
   runnableExamples:
     let
       a = 62'u64
@@ -963,34 +963,7 @@ proc toHex*(x: BiggestUInt, len: Positive): string {.noSideEffect.} =
     doAssert a.toHex(3) == "03E"
     doAssert b.toHex(3) == "001"
     doAssert b.toHex(4) == "1001"
-  toHexImpl(x, len, false)
-
-proc toHex*(x: BiggestInt, len: Positive): string {.noSideEffect,
-  rtl, extern: "nsuToHex".} =
-  ## Converts `x` to its hexadecimal representation.
-  ##
-  ## The resulting string will be exactly `len` characters long. No prefix like
-  ## ``0x`` is generated. `x` is treated as an unsigned value.
-  runnableExamples:
-    let
-      a = 62
-      b = 4097
-      c = -8
-    doAssert a.toHex(3) == "03E"
-    doAssert b.toHex(3) == "001"
-    doAssert b.toHex(4) == "1001"
-    doAssert c.toHex(6) == "FFFFF8"
-  toHexImpl(cast[BiggestUInt](x), len, x < 0)
-
-proc toHex*(x: int, len: Positive): string {.noSideEffect.} =
-  ## Converts `x` to its hexadecimal representation.
-  ##
-  ## The resulting string will be exactly `len` characters long. No prefix like
-  ## ``0x`` is generated. `x` is treated as an unsigned value.
-  runnableExamples:
     doAssert toHex(62, 3) == "03E"
-    doAssert toHex(4097, 3) == "001"
-    doAssert toHex(4097, 4) == "1001"
     doAssert toHex(-8, 6) == "FFFFF8"
   toHexImpl(cast[BiggestUInt](x), len, x < 0)