Better string escaping algorithm

Signed-off-by: K-ballo <k@fusionfenix.com>