reenable Defect raises for Nim 1.2
This commit is contained in:
parent
faabd40c30
commit
6cc42beac7
|
@ -18,14 +18,16 @@ export arrayops.`&`, arrayops.initArrayWith, arrayops.`[]=`
|
|||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
{.pragma: hexRaises, raises: [Defect, ValueError].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.pragma: hexRaises, raises: [ValueError].}
|
||||
|
||||
########################################################################################################
|
||||
##################################### Hex utilities ################################################
|
||||
|
||||
proc readHexChar*(c: char): byte
|
||||
{.raises: [ValueError], noSideEffect, inline.} =
|
||||
{.hexRaises, noSideEffect, inline.} =
|
||||
## Converts an hex char to a byte
|
||||
case c
|
||||
of '0'..'9': result = byte(ord(c) - ord('0'))
|
||||
|
@ -42,7 +44,7 @@ template skip0xPrefix(hexStr: openArray[char]): int =
|
|||
|
||||
func hexToByteArrayImpl(
|
||||
hexStr: openArray[char], output: var openArray[byte], fromIdx, toIdx: int):
|
||||
int {.raises: [ValueError].} =
|
||||
int {.hexRaises.} =
|
||||
var sIdx = skip0xPrefix(hexStr)
|
||||
# Fun with closed intervals
|
||||
doAssert fromIdx >= 0 and
|
||||
|
@ -65,7 +67,7 @@ func hexToByteArrayImpl(
|
|||
|
||||
func hexToByteArray*(
|
||||
hexStr: openArray[char], output: var openArray[byte], fromIdx, toIdx: int)
|
||||
{.raises: [ValueError].} =
|
||||
{.hexRaises.} =
|
||||
## Read hex-encoded data from `hexStr[mapHex(fromIdx..toIdx)]` and store
|
||||
## corresponding bytes in `output[fromIdx..toIdx]` where `mapHex` takes into
|
||||
## account stripped characters.
|
||||
|
@ -80,7 +82,7 @@ func hexToByteArray*(
|
|||
discard hexToByteArrayImpl(hexStr, output, fromIdx, toIdx)
|
||||
|
||||
func hexToByteArray*(hexStr: openArray[char], output: var openArray[byte])
|
||||
{.raises: [ValueError].} =
|
||||
{.hexRaises.} =
|
||||
## Read hex-encoded data from `hexStr` and store corresponding bytes in
|
||||
## `output`.
|
||||
##
|
||||
|
@ -92,7 +94,7 @@ func hexToByteArray*(hexStr: openArray[char], output: var openArray[byte])
|
|||
hexToByteArray(hexStr, output, 0, output.high)
|
||||
|
||||
func hexToByteArray*[N: static[int]](hexStr: openArray[char]): array[N, byte]
|
||||
{.raises: [ValueError], noinit.}=
|
||||
{.hexRaises, noinit.}=
|
||||
## Read hex-encoded data from `hexStr` returning an array of N bytes.
|
||||
##
|
||||
## * `0x`/`0X` is stripped if present
|
||||
|
@ -103,7 +105,7 @@ func hexToByteArray*[N: static[int]](hexStr: openArray[char]): array[N, byte]
|
|||
hexToByteArray(hexStr, result)
|
||||
|
||||
func hexToByteArray*(hexStr: openArray[char], N: static int): array[N, byte]
|
||||
{.raises: [ValueError], noinit.}=
|
||||
{.hexRaises, noinit.}=
|
||||
## Read hex-encoded data from `hexStr` returning an array of N bytes.
|
||||
##
|
||||
## * `0x`/`0X` is stripped if present
|
||||
|
@ -114,7 +116,7 @@ func hexToByteArray*(hexStr: openArray[char], N: static int): array[N, byte]
|
|||
hexToByteArray(hexStr, result)
|
||||
|
||||
func hexToByteArrayStrict*(hexStr: openArray[char], output: var openArray[byte])
|
||||
{.raises: [ValueError].} =
|
||||
{.hexRaises.} =
|
||||
## Read hex-encoded data from `hexStr` and store corresponding bytes in
|
||||
## `output`.
|
||||
##
|
||||
|
@ -126,7 +128,7 @@ func hexToByteArrayStrict*(hexStr: openArray[char], output: var openArray[byte])
|
|||
raise (ref ValueError)(msg: "hex string too long")
|
||||
|
||||
func hexToByteArrayStrict*[N: static[int]](hexStr: openArray[char]): array[N, byte]
|
||||
{.raises: [ValueError, Defect], noinit, inline.}=
|
||||
{.hexRaises, noinit, inline.}=
|
||||
## Read hex-encoded data from `hexStr` and store corresponding bytes in
|
||||
## `output`.
|
||||
##
|
||||
|
@ -137,7 +139,7 @@ func hexToByteArrayStrict*[N: static[int]](hexStr: openArray[char]): array[N, by
|
|||
hexToByteArrayStrict(hexStr, result)
|
||||
|
||||
func hexToByteArrayStrict*(hexStr: openArray[char], N: static int): array[N, byte]
|
||||
{.raises: [ValueError, Defect], noinit, inline.}=
|
||||
{.hexRaises, noinit, inline.}=
|
||||
## Read hex-encoded data from `hexStr` and store corresponding bytes in
|
||||
## `output`.
|
||||
##
|
||||
|
@ -148,7 +150,7 @@ func hexToByteArrayStrict*(hexStr: openArray[char], N: static int): array[N, byt
|
|||
hexToByteArrayStrict(hexStr, result)
|
||||
|
||||
func fromHex*[N](A: type array[N, byte], hexStr: string): A
|
||||
{.raises: [ValueError], noinit, inline.}=
|
||||
{.hexRaises, noinit, inline.}=
|
||||
## Read hex-encoded data from `hexStr` returning an array of N bytes.
|
||||
##
|
||||
## * `0x`/`0X` is stripped if present
|
||||
|
@ -159,7 +161,7 @@ func fromHex*[N](A: type array[N, byte], hexStr: string): A
|
|||
hexToByteArray(hexStr, result)
|
||||
|
||||
func hexToPaddedByteArray*[N: static[int]](hexStr: string): array[N, byte]
|
||||
{.raises: [ValueError].} =
|
||||
{.hexRaises.} =
|
||||
## Read a hex string and store it in a byte array `output`.
|
||||
## The string may be shorter than the byte array.
|
||||
## No "endianness" reordering is done.
|
||||
|
@ -188,7 +190,7 @@ func hexToPaddedByteArray*[N: static[int]](hexStr: string): array[N, byte]
|
|||
bIdx += shift shr 2
|
||||
|
||||
func hexToSeqByte*(hexStr: string): seq[byte]
|
||||
{.raises: [ValueError].} =
|
||||
{.hexRaises.} =
|
||||
## Read an hex string and store it in a sequence of bytes. No "endianness" reordering is done.
|
||||
if (hexStr.len and 1) == 1:
|
||||
raise (ref ValueError)(msg: "hex string must have even length")
|
||||
|
|
Loading…
Reference in New Issue