Cleanup unused vars, move unEscape and add tests

This commit is contained in:
kortschak 2014-07-25 11:35:48 +09:30
parent d76213fb2d
commit 92baa2ecee
3 changed files with 87 additions and 66 deletions

View file

@ -17,10 +17,8 @@
package nquads
import (
"bytes"
"errors"
"fmt"
"strconv"
"unicode"
"github.com/google/cayley/graph"
@ -63,59 +61,3 @@ func parse(data []rune) (graph.Triple, error) {
return graph.Triple{}, ErrInvalid
}
func unEscape(r []rune, isEscaped bool) string {
if !isEscaped {
return string(r)
}
buf := bytes.NewBuffer(make([]byte, 0, len(r)))
for i := 0; i < len(r); {
switch r[i] {
case '\\':
i++
var c byte
switch r[i] {
case 't':
c = '\t'
case 'b':
c = '\b'
case 'n':
c = '\n'
case 'r':
c = '\r'
case 'f':
c = '\f'
case '"':
c = '"'
case '\'':
c = '\''
case '\\':
c = '\\'
case 'u':
rc, err := strconv.ParseInt(string(r[i+1:i+5]), 16, 32)
if err != nil {
panic(fmt.Errorf("internal parser error: %v", err))
}
buf.WriteRune(rune(rc))
i += 5
continue
case 'U':
rc, err := strconv.ParseInt(string(r[i+1:i+9]), 16, 32)
if err != nil {
panic(fmt.Errorf("internal parser error: %v", err))
}
buf.WriteRune(rune(rc))
i += 9
continue
}
buf.WriteByte(c)
default:
buf.WriteRune(r[i])
}
i++
}
return buf.String()
}