This PR adds a CStringEscaper class that escapes and unescapes strings in C-style (e.g., \', \", \r, \n).
The string escapes in StrategoString have been replaced by calls to this new class. The class does the same escapes (double quotes, not single quotes, and backslashes), but also escapes control codes that cannot be displayed. Most importantly, it works more efficiently as it walks over the string only once instead of however many times replace() was called in the original code. For writeAsString() the implementation directly writes to the Appendable whereas the original implementation created intermediate strings.
Can you add a companion PR for SPT? I've found another instance of this kind of escaping in spt/org.metaborg.spt.core/src/main/java/org/metaborg/spt/core/SPTUtil.java.
This PR adds a
CStringEscaper
class that escapes and unescapes strings in C-style (e.g.,\'
,\"
,\r
,\n
).The string escapes in
StrategoString
have been replaced by calls to this new class. The class does the same escapes (double quotes, not single quotes, and backslashes), but also escapes control codes that cannot be displayed. Most importantly, it works more efficiently as it walks over the string only once instead of however many timesreplace()
was called in the original code. ForwriteAsString()
the implementation directly writes to theAppendable
whereas the original implementation created intermediate strings.The implementation is verified by 1444 tests.