lexer: add re-quote helper

This commit is contained in:
mappu 2024-06-29 11:56:26 +12:00
parent 639da11ab3
commit f0f0ff7904
1 changed files with 5 additions and 0 deletions

View File

@ -2,12 +2,17 @@ package lexer
import ( import (
"fmt" "fmt"
"strings"
) )
func isWhitespace(r byte) bool { func isWhitespace(r byte) bool {
return (r == ' ' || r == '\t' || r == '\r' || r == '\n') return (r == ' ' || r == '\t' || r == '\r' || r == '\n')
} }
func Quote(input string) string {
return `"` + strings.ReplaceAll(strings.ReplaceAll(input, `\`, `\\`), `"`, `\"`) + `"`
}
// Fields splits a string into separate tokens using something kind of vaguely // Fields splits a string into separate tokens using something kind of vaguely
// like how SQL would do it. // like how SQL would do it.
// The result still includes the quote and backslash characters. // The result still includes the quote and backslash characters.