Is your feature request related to a problem? Please describe.
Compilers and tooling require a lot of annoying string processing, one of which is unescaping the escape sequences in strings. This is usually required for parsed string literals and regexes. This involves turning \n, \r, ... into the appropriate characters.
Sometimes, the opposite is required, when a string is given, and the user wants the escaped representation.
Describe the solution you'd like
We should provide two methods, one for escaping and one for unescaping strings. Yoakke.Text seems like the ideal place to put it. For example, Unescape("\\thello\\n") should result in "\thello\n" and Escape("\thello\n") should result in "\\thello\\n".
Somehow we should also annotate, which escapes we want to allow (maybe even custom escape sequences, can be really useful for lexing custom formats). Also, supporting unicode codepoint escapes would be nice, just like \Unnnn or \unnnnnnnn
Describe alternatives you've considered
The API is not clear in my head yet, but 2 basic signatures could be:
StringEscapes.Escape(ReadOnlySpan<char>)
StringEscapes.Unescape(ReadOnlySpan<char>)
This does not yet detail, how we want the feature to be customizable, I haven't thought of it yet.
Is your feature request related to a problem? Please describe.
Compilers and tooling require a lot of annoying string processing, one of which is unescaping the escape sequences in strings. This is usually required for parsed string literals and regexes. This involves turning
\n,\r, ... into the appropriate characters.Sometimes, the opposite is required, when a string is given, and the user wants the escaped representation.
Describe the solution you'd like
We should provide two methods, one for escaping and one for unescaping strings.
Yoakke.Textseems like the ideal place to put it. For example,Unescape("\\thello\\n")should result in"\thello\n"andEscape("\thello\n")should result in"\\thello\\n".Somehow we should also annotate, which escapes we want to allow (maybe even custom escape sequences, can be really useful for lexing custom formats). Also, supporting unicode codepoint escapes would be nice, just like
\Unnnnor\unnnnnnnnDescribe alternatives you've considered
The API is not clear in my head yet, but 2 basic signatures could be:
StringEscapes.Escape(ReadOnlySpan<char>)StringEscapes.Unescape(ReadOnlySpan<char>)This does not yet detail, how we want the feature to be customizable, I haven't thought of it yet.