Reduce amount of copying and character lookup when escaping strings.