I've just released a new library for generating escaped strings in various formats.
https://github.com/semantalytics-stardog/kibbles-string-escape/releases
There are functions for escaping and unescaping the following formats
csv
ecmaScript
html3
html4
java
json
xml
xml10
xml11
xsi