Optimized string escaping.

This implementation supports Unicode as well.