StringUnEscape remove escaping on string that may need characters escaped StringUnEscape(`"`,`item"s`) => "item""s", true
(quote rune, val string)
| 214 | // StringUnEscape(`"`,`item"s`) => "item""s", true |
| 215 | // |
| 216 | func StringUnEscape(quote rune, val string) (string, bool) { |
| 217 | var buf bytes.Buffer |
| 218 | prevEscape, hasEscape := false, false |
| 219 | for _, r := range val { |
| 220 | if r == quote && prevEscape { |
| 221 | hasEscape = true |
| 222 | buf.WriteByte(byte(r)) |
| 223 | prevEscape = false |
| 224 | } else if r == quote { |
| 225 | prevEscape = true |
| 226 | } else if r == '\\' { |
| 227 | prevEscape = true |
| 228 | } else { |
| 229 | buf.WriteByte(byte(r)) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | return buf.String(), hasEscape |
| 234 | } |
| 235 | |
| 236 | // A break, is some character such as comma, ;, whitespace |
| 237 | func isBreak(r rune) bool { |