1
0
mirror of https://github.com/json-iterator/go.git synced 2025-01-08 13:06:29 +02:00

skip tab; add CurrentBuffer() to allow debug

This commit is contained in:
Tao Wen 2016-12-05 10:43:42 +08:00
parent 7d8dcb7ec4
commit 7a507e6bf3

View File

@ -43,7 +43,7 @@ func ParseString(input string) *Iterator {
func (iter *Iterator) skipWhitespaces() {
c := iter.readByte()
for c == ' ' || c == '\n' {
for c == ' ' || c == '\n' || c == '\t' {
c = iter.readByte()
}
iter.unreadByte()
@ -58,6 +58,15 @@ func (iter *Iterator) ReportError(operation string, msg string) {
string(iter.buf[peekStart: iter.head]), string(iter.buf[0:iter.tail]))
}
func (iter *Iterator) CurrentBuffer() string {
peekStart := iter.head - 10
if peekStart < 0 {
peekStart = 0
}
return fmt.Sprintf("parsing %v ...%s... at %s", iter.head,
string(iter.buf[peekStart: iter.head]), string(iter.buf[0:iter.tail]))
}
func (iter *Iterator) readByte() (ret byte) {
if iter.head == iter.tail {
if iter.reader == nil {