RemoveEscapeChar removes escape characters
(word string)
| 644 | |
| 645 | // RemoveEscapeChar removes escape characters |
| 646 | func RemoveEscapeChar(word string) string { |
| 647 | // Fast path: check if there are any escape characters first |
| 648 | escapeIdx := strings.IndexByte(word, '\\') |
| 649 | if escapeIdx == -1 { |
| 650 | return word // No escape chars, return original string without allocation |
| 651 | } |
| 652 | |
| 653 | // Slow path: copy and remove escape characters |
| 654 | b := []byte(word) |
| 655 | dst := escapeIdx |
| 656 | for src := escapeIdx + 1; src < len(b); src++ { |
| 657 | if b[src] != '\\' { |
| 658 | b[dst] = b[src] |
| 659 | dst++ |
| 660 | } |
| 661 | } |
| 662 | return string(b[:dst]) |
| 663 | } |
| 664 | |
| 665 | // RemoveEscapeCharBytes removes escape characters |
| 666 | func RemoveEscapeCharBytes(word []byte) []byte { |
no outgoing calls