3 ms·
> I had forgotten that escape sequences needed to also be changed. Unescaping in place does make it non-trivial. Assuming escapes are rare, backshift unescapin
by formerly_proven 6y ago
> I had forgotten that escape sequences needed to also be changed. Unescaping in place does make it non-trivial.
Assuming escapes are rare, backshift unescaping is totally an option, though it scales poorly (interpreting escapes is linear, backshifting is quadratic) and is thus susceptible to slowdowns with malicious inputs. It does need very little code and no extra memory at all, though.
- fanf2 6y agoBackshifting is not quadratic :-) dst = src = ptr; while(*src != '\0') { if(src[0] == '"' && src[1] == '"') { src++; } *dst++ = *src++; }
- formerly_proven 6y agoThis bothered me a little, so I went and dug out the only instance were I remember using this technique, and it's quite literally what you wrote. All these high level immutable languages must be getting to me. Thanks :)