Properly escape some control chars (and generalized it)