implement octal escapes in double quotes

Mentioned in #47.
This commit is contained in:
Gokcehan committed 2017-03-16 00:13:26 +03:00
1 parent 7d21785af7
commit 784d80ca30
2 files changed
+31 -1

No files matched your search

+12
View File
@@ -71,6 +71,18 @@ var gEvalTests = []struct {
[]expr{&callExpr{"echo", []string{"helloworld"}}},
},
{
`echo "hello\0world"`,
[]string{"echo", "hello\000world", "\n"},
[]expr{&callExpr{"echo", []string{"hello\000world"}}},
},
{
`echo "hello\101world"`,
[]string{"echo", "hello\101world", "\n"},
[]expr{&callExpr{"echo", []string{"hello\101world"}}},
},
{
`echo hello\ world`,
[]string{"echo", "hello world", "\n"},
+19 -1
View File
@@ -4,6 +4,7 @@ import (
"io"
"io/ioutil"
"log"
"strconv"
"unicode"
)
@@ -84,6 +85,10 @@ func isSpace(b byte) bool {
return unicode.IsSpace(rune(b))
}
func isDigit(b byte) bool {
return unicode.IsDigit(rune(b))
}
func isPrefix(b byte) bool {
// TODO: how to differentiate slash in path vs search?
return b == '$' || b == '!' || b == '&' // || b == '/' || b == '?'
@@ -228,7 +233,20 @@ scan:
case 'v':
buf = append(buf, '\v')
}
s.next()
if isDigit(s.chr) {
var oct []byte
for isDigit(s.chr) {
oct = append(oct, s.chr)
s.next()
}
n, err := strconv.ParseInt(string(oct), 8, 0)
if err != nil {
log.Printf("scanning: %s", err)
}
buf = append(buf, byte(n))
} else {
s.next()
}
} else {
buf = append(buf, s.chr)
s.next()