[SOLVED] Anyone having a stringify function circumventing :put to displaying un-printable characters as HEX escapes?

While researching Why does get for static DNS and DHCP leases have issues with nulls in string values and how can I work around it? I think I found the culprit:

:put won’t HEX-escape the characters it cannot print. Some examples are below.

JavaScript has a JSON.stringify for this (example at http://stackoverflow.com/questions/21672334/javascript-how-to-show-escape-characters-in-a-string/21672392#21672392)

Is there such a function for the Scripting engine?

:put "a\00b"
ab
:put "a\01b" 
ab
:put "a\02b" 
ab
:put "a\03b" 
ab
:put "a\04b" 
ab
:put "a\05b" 
ab
:put "a\06b" 
ab
:put "a\07b" 
ab
:put "a\08b" 
b
:put "a\09b" 
a	b
:put "a\10b"  
ab
:put "a\11b" 
ab
:put "a\12b" 
ab
:put "a\13b" 
ab
:put "a\14b" 
ab
:put "a\15b" 
ab
:put "a\16b" 
ab
:put "a\17b" 
ab
:put "a\18b" 
ab
:put "a\19b" 
ab
:put "a\20b"  
a b
:put "a\FFb"  
a?b
:put "a\FEb"  
a?b
:put "a\FDb" 
a?b
:put "a\F0b" 
a?b
:put "a\E0b" 
a?b
:put "a\D0b" 
a?b
:put "a\C0b" 
a?b
:put "a\B0b" 
a?b
:put "a\A0b" 
a?b
:put "a\90b" 
a?b
:put "a\80b" 
a?b
:put "a\70b" 
apb




Nope.

If you actually make one, and ask MikroTik for a wiki account, I’m sure they’ll make you one, at which point you can add it to the wiki.


I’ve been meaning to make something similar (more akin to PHP’s var_dump()), but I’ve only ever gotten half way through, and didn’t even considered unprintable characters. I’d love to have such a function, as I’ve been needing it myself on multiple occasions.

Thanks. Let me know what you have so I can extend.

This is a start: https://gist.github.com/jpluimers/f667af4696d2a6411be44df1eeda2c2f