Source   Edit  


proc decodePercent(s: openArray[char]; i: var int): char {....raises: [], tags: [],
    forbids: [].}

Converts %xx hexadecimal to the character with ordinal number xx.

If xx is not a valid hexadecimal value, it is left intact: only the leading % is returned as-is, and xx characters will be processed in the next step (e.g. in uri.decodeUrl) as regular characters.

Source   Edit  
proc handleHexChar(c: char): int {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc handleHexChar(c: char; x: var int): bool {.inline, ...raises: [], tags: [],
    forbids: [].}

Converts %xx hexadecimal to the ordinal number and adds the result to x. Returns true if c is hexadecimal.

When c is hexadecimal, the proc is equal to x = x shl 4 + hex2Int(c).


var x = 0
assert handleHexChar('a', x)
assert x == 10

assert handleHexChar('B', x)
assert x == 171 # 10 shl 4 + 11

assert not handleHexChar('?', x)
assert x == 171 # unchanged
Source   Edit