core :: Bytes :: chexdigest
\x
The output is compatible with literal stream of bytes for most languages including C and Nit.
var b = "abcd".to_bytes
assert b.chexdigest == "\\x61\\x62\\x63\\x64"
assert b.chexdigest.unescape_to_bytes == b
# Return self as a C hexadecimal digest where bytes are prefixed by `\x`
#
# The output is compatible with literal stream of bytes for most languages
# including C and Nit.
#
# ~~~
# var b = "abcd".to_bytes
# assert b.chexdigest == "\\x61\\x62\\x63\\x64"
# assert b.chexdigest.unescape_to_bytes == b
# ~~~
fun chexdigest: String do
var elen = length * 4
var ns = new CString(elen)
var i = 0
var oi = 0
while i < length do
ns[oi] = u'\\'
ns[oi+1] = u'x'
self[i].add_digest_at(ns, oi+2)
i += 1
oi += 4
end
return new FlatString.full(ns, elen, 0, elen)
end
lib/core/bytes.nit:384,2--407,4