Parser
Holder for ranges of characters and their associated DecoderAction with support for constant-time operations (in terms of work performed for provided input).
e.g. (NOT constant-time operation)
fun String.containsChar(char: Char): Boolean {
for (c in this) {
if (c == char) return true
}
return false
}
Content copied to clipboard
e.g. (YES constant-time operation)
fun String.containsChar(char: Char): Boolean {
var result = false
for (c in this) {
result = if (c == char) true else result
}
return result
}
Content copied to clipboard
e.g. (Base16)
val parser = DecoderAction.Parser(
'0'..'9' to DecoderAction { char ->
char.code - 48
},
'A'..'Z' to DecoderAction { char ->
char.code - 55
}
)
val bits = "48656C6C6F20576F726C6421".map { char ->
parser.parse(char, isConstantTime = true)
?: error("Invalid Char[$char]")
}
Content copied to clipboard
Parameters
action
Pairs of character ranges and their associated DecoderAction
Functions
Link copied to clipboard
Parses the actions for containing input, invoking the DecoderAction.convert for that associated range of characters.