Doing a single slash means the next character or two are expected to form a valid escape sequence. “\0” on its own is not a valid escape sequence, unless you have a literal second hex character there, e.g. “\0F”.
To put this another way, on a parser level,
"\0".$hexChar
is three main tokens: a string, a concatenation operator, and a variable access operator. Within a string, each character other than a slash is valid, but a slash must either be followed by one of the second characters from the constant escape sequences, or the next two characters must form a valid hex number.
That I already figured. Hence the above question: How can I do this despite the parser?
Is there a kind of eval or parse function that I could use? And if so: where should I start?
Yes. There’s the :parse command. It takes a string, and returns a callable command. If you store it in a variable, then referencing the variable will trigger the command.
(that one’s been in use from before :local and :global could declare functions with the “do” argument)
There’s also :execute, which is similar, but instead of returning the command, is executes it right away. It’s “the” equivalent of eval().
Obviously, it’s slower than executing the actual code directly, but AFAIK, it’s not THAT much slower (I haven’t done any measurements, but there’s certainly not a noticeable difference). The penalty adds up if you call :parse/:execute multiple times, but if you compose everything, before eventually calling it once, there shouldn’t be much different, compared to executing the generation, and then executing “real code equivalent”.
The larger parts of your performance concerns should be at the actual generation, as there’s no “append” operation for strings. Every concatenation produces a new value, and then you overwrite the old value, and you do that each time you want to append to a string, which is not exactly very efficient, and adds up on large loops. I don’t think 150 overwrites add THAT much time, but still, it would be noticeably slower if you were comparing 1000 times here with 1000 time in any language supporting operators like “+=” or “.=”.
Something do not work on your script, this topic “How to convert a HEX value to a char?” is fo convert hexadecimal values to characters.
On this test I use equal sign “=” that is 0x3D on hex, my function works, your not.
Probably your line is for convert a 0-255 number to a 8-bit character.
I prefer write code than after some month I keep understand what is wrote without go mad,
and I avoid rewriting the same strings and redoing the same operations several times (“0123…”, [:tonum $1])
I apologize for not answering for a long time. The function is used to get a character by code, and if $1 is not set, then it returns a character string of all codes of page.