Here's something to mull over.
Warning: this code may look scarily compact.
A string can be spliced with [:n] even if the string is shorter than length n.
Using unicode-escape to encode the string helpfully stops escape sequences. However, this may not be what some people want. The difference here is that it does not destroy bad escape sequences, but rather stops them from being bad.
A lot less code.
If you aren't going to merge this, d23a3a3 should probably be reverted.
Here's something to mull over. Warning: this code may look scarily compact.
[:n]
even if the string is shorter than lengthn
.unicode-escape
to encode the string helpfully stops escape sequences. However, this may not be what some people want. The difference here is that it does not destroy bad escape sequences, but rather stops them from being bad.If you aren't going to merge this, d23a3a3 should probably be reverted.