strings.go 483 B

123456789101112131415161718192021
  1. package escape
  2. import "strings"
  3. var (
  4. escaper = strings.NewReplacer(`,`, `\,`, `"`, `\"`, ` `, `\ `, `=`, `\=`)
  5. unescaper = strings.NewReplacer(`\,`, `,`, `\"`, `"`, `\ `, ` `, `\=`, `=`)
  6. )
  7. // UnescapeString returns unescaped version of in.
  8. func UnescapeString(in string) string {
  9. if strings.IndexByte(in, '\\') == -1 {
  10. return in
  11. }
  12. return unescaper.Replace(in)
  13. }
  14. // String returns the escaped version of in.
  15. func String(in string) string {
  16. return escaper.Replace(in)
  17. }