Skip to content

Commit

Permalink
boyscout: clean up switch cases so they all line up vertically. Makes…
Browse files Browse the repository at this point in the history
… the cases easier to read
  • Loading branch information
chewxy committed Dec 23, 2020
1 parent 444fa1a commit 9de70ae
Showing 1 changed file with 36 additions and 38 deletions.
74 changes: 36 additions & 38 deletions lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ func (s *Lexer) readString() (Token, *gqlerror.Error) {

escape := s.Input[s.end+1]

if escape == 'u' {
switch escape {
case 'u':
if s.end+6 >= inputLen {
s.end++
s.endRunes++
Expand All @@ -377,49 +378,46 @@ func (s *Lexer) readString() (Token, *gqlerror.Error) {
return s.makeError("Invalid character escape sequence: \\%s.", s.Input[s.end:s.end+5])
}
buf.WriteRune(r)
s.end += 6
s.endRunes += 6
} else {
switch escape {
case '"', '/', '\\':
buf.WriteByte(escape)
case 'b':
buf.WriteByte('\b')
case 'f':
buf.WriteByte('\f')
case 'n':
buf.WriteByte('\n')
case 'r':
buf.WriteByte('\r')
case 't':
buf.WriteByte('\t')
case 'x':
if s.end+4 >= inputLen {
s.end++
s.endRunes++
break
}
// look two ahead
r, ok := unhex2(s.Input[s.end+2 : s.end+4])
if !ok {
// if it's not a correct rune, then we treat it as a literal and move o
buf.WriteString(s.Input[s.end : s.end+2])
s.end += 2
s.endRunes += 2
continue
}
buf.WriteRune(r)
s.end += 4 // because at the end of this we're going to += 2
s.endRunes += 4
case '"', '/', '\\':
buf.WriteByte(escape)
case 'b':
buf.WriteByte('\b')
case 'f':
buf.WriteByte('\f')
case 'n':
buf.WriteByte('\n')
case 'r':
buf.WriteByte('\r')
case 't':
buf.WriteByte('\t')
case 'x':
if s.end+4 >= inputLen {
s.end++
s.endRunes++
break
}
// look two ahead
r, ok := unhex2(s.Input[s.end+2 : s.end+4])
if !ok {
// if it's not a correct rune, then we treat it as a literal and move o
buf.WriteString(s.Input[s.end : s.end+2])
s.end += 2
s.endRunes += 2

default:
s.end += 1
s.endRunes += 1
return s.makeError("Invalid character escape sequence: \\%s.", string(escape))
continue
}
buf.WriteRune(r)
s.end += 2
s.endRunes += 2

default:
s.end += 1
s.endRunes += 1
return s.makeError("Invalid character escape sequence: \\%s.", string(escape))
}
s.end += 2
s.endRunes += 2
}
}

Expand Down

0 comments on commit 9de70ae

Please sign in to comment.