Encapsulate string escape functionality

In case this can be used in other places.
Also escape slashes and other special characters