MCPcopy Create free account
hub / github.com/araddon/qlbridge / StringUnEscape

Function StringUnEscape

expr/stringutil.go:216–234  ·  view source on GitHub ↗

StringUnEscape remove escaping on string that may need characters escaped StringUnEscape(`"`,`item"s`) => "item""s", true

(quote rune, val string)

Source from the content-addressed store, hash-verified

214// StringUnEscape(`"`,`item"s`) => "item""s", true
215//
216func 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
237func isBreak(r rune) bool {

Callers 3

TestLiteralEscapingFunction · 0.85
NewStringNeedsEscapeFunction · 0.85
ValueArrayFunction · 0.85

Calls 1

StringMethod · 0.65

Tested by 1

TestLiteralEscapingFunction · 0.68