Reworks string storage... again. Back to unescaping on parse. But now we escape on raw print.

master
sloum 2 years ago
parent 0f5586b3d6
commit cf750b2282

@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"syscall"
"unicode"
)
func AnythingToBool(e expression) expression {
@ -137,7 +138,11 @@ func escapeString(s string) string {
case '\\':
out.WriteString("\\\\")
default:
out.WriteRune(c)
if !unicode.IsPrint(c) {
out.WriteString(fmt.Sprintf("\\0%o", c))
} else {
out.WriteRune(c)
}
}
}
return out.String()

@ -16,7 +16,9 @@ func eval(exp expression, en *env) (value expression) {
switch e := exp.(type) {
case symbol:
value = en.Find(e).vars[e]
case bool, number, string:
case string:
value = unescapeString(e)
case bool, number:
value = e
case exception:
if panicOnException {

@ -47,7 +47,7 @@ func String(v expression, rawString bool) string {
return "(" + strings.Join(l, " ") + ")"
case string:
if rawString {
return fmt.Sprintf("\"%s\"", v)
return fmt.Sprintf("\"%s\"", escapeString(v))
}
return unescapeString(v)
case exception:

Loading…
Cancel
Save