EscapeStringLiterals escapes backslashes in string literals within an expression to ensure consistent handling between govaluate (which interprets escape sequences) and CSV parsing (which treats backslashes as literal characters). This function doubles all backslashes within single-quoted and double
(expr string)
| 281 | // and CSV parsing (which treats backslashes as literal characters). |
| 282 | // This function doubles all backslashes within single-quoted and double-quoted strings. |
| 283 | func EscapeStringLiterals(expr string) string { |
| 284 | var result strings.Builder |
| 285 | inString := false |
| 286 | var quote rune |
| 287 | |
| 288 | for i := 0; i < len(expr); i++ { |
| 289 | ch := rune(expr[i]) |
| 290 | |
| 291 | if inString { |
| 292 | result.WriteRune(ch) |
| 293 | if ch == '\\' { |
| 294 | // Found a backslash inside a string - double it |
| 295 | result.WriteRune('\\') |
| 296 | } else if ch == quote { |
| 297 | // End of string literal |
| 298 | inString = false |
| 299 | } |
| 300 | continue |
| 301 | } |
| 302 | |
| 303 | // Not inside a string literal |
| 304 | if ch == '\'' || ch == '"' { |
| 305 | inString = true |
| 306 | quote = ch |
| 307 | } |
| 308 | result.WriteRune(ch) |
| 309 | } |
| 310 | |
| 311 | return result.String() |
| 312 | } |
| 313 | |
| 314 | func RemoveDuplicateElement(s []string) []string { |
| 315 | result := make([]string, 0, len(s)) |
searching dependent graphs…