Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Jun 4, 2018
1 parent 578d841 commit f207c62
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions graphql/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import (
"strconv"
)

const alphabet = "0123456789ABCDEF"
const encodeHex = "0123456789ABCDEF"

func MarshalString(s string) Marshaler {
return WriterFunc(func(w io.Writer) {
start := 0
io.WriteString(w, `"`)

for i := 0; i < len(s); i++ {
c := s[i]

for i, c := range s {
if c < 0x20 || c == '\\' || c == '"' {
io.WriteString(w, s[start:i])

Expand All @@ -32,7 +30,7 @@ func MarshalString(s string) Marshaler {
io.WriteString(w, `\"`)
default:
io.WriteString(w, `\u00`)
w.Write([]byte{alphabet[c>>4], alphabet[c&0xf]})
w.Write([]byte{encodeHex[c>>4], encodeHex[c&0xf]})
}

start = i + 1
Expand Down

0 comments on commit f207c62

Please sign in to comment.