Re: unescape \n \r etc in string

2016-12-16 Thread cblake
Looking at the implementation of strutils.unescape, it seems to only interpret 
the xHH syntax that escape outputs. Of course, the compiler proper is often 
changing those raw/quoted string forms into special characters. So, maybe there 
is some other approach/trick that could work..sort of like an "eval" in 
interpreted languages.


Re: unescape \n \r etc in string

2016-12-15 Thread vlad1777d
@Krux02, maybe this is a bug, you could post an issue on GitHub.


Re: unescape \n \r etc in string

2016-12-15 Thread Krux02
no, I am asking for the inverse of that function. There is unescape, but it 
doesn't do what I want to do:


import strutils

let str = r"\n\r"

echo str
assert unescape(str, "", "") == "\n\r"



Re: unescape \n \r etc in string

2016-12-15 Thread cblake
Perhaps you want strutils.escape? I.e.: 


import strutils
echo escape("\n\t")


Output is "\x0A\x09"

Its output is designed to be as portable an 'input' to 
de-escapers/escape-interpreters as possible. So you will see things like \x0A 
and \x09 instead of the \n \t because the former syntax is accepted by more 
string parsers.


unescape \n \r etc in string

2016-12-15 Thread Krux02
I have a macro with a string argument. The string is partially preserved, but 
all n from the string are now litterally n and t. so how do I unescape 
thesevalues to create a string object out of them? All my ideas right now feel 
like a lot of work with some uncertenty if I did everything correct, so I 
thought I might better ask, even though the implementation is propably trivial 
I do not think that the correct implementation is.