Skip to content

Commit

Permalink
Merge pull request #27 from goccy/feature/fix-multi-bytes-handling
Browse files Browse the repository at this point in the history
Fix multi bytes handling
  • Loading branch information
goccy authored Nov 7, 2019
2 parents 0863153 + 41320de commit bc661e8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ func TestDecoder(t *testing.T) {

// Multi bytes
{
"v: あいうえお",
map[string]string{"v": "あいうえお"},
"v: あいうえお\nv2: かきくけこ",
map[string]string{"v": "あいうえお", "v2": "かきくけこ"},
},
}
for _, test := range tests {
Expand Down
4 changes: 2 additions & 2 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ func TestEncoder(t *testing.T) {

// Multi bytes
{
"v: あいうえお\n",
map[string]string{"v": "あいうえお"},
"v: あいうえお\nv2: かきくけこ\n",
map[string]string{"v": "あいうえお", "v2": "かきくけこ"},
},
}
for _, test := range tests {
Expand Down
3 changes: 1 addition & 2 deletions scanner/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ type Context struct {
literalOpt string
}

func newContext(s string) *Context {
src := []rune(s)
func newContext(src []rune) *Context {
return &Context{
idx: 0,
size: len(src),
Expand Down
5 changes: 3 additions & 2 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
// Scanner holds the scanner's internal state while processing a given text.
// It can be allocated as part of another data structure but must be initialized via Init before use.
type Scanner struct {
source string
source []rune
sourcePos int
sourceSize int
line int
Expand Down Expand Up @@ -486,7 +486,8 @@ func (s *Scanner) scan(ctx *Context) (pos int) {
}

// Init prepares the scanner s to tokenize the text src by setting the scanner at the beginning of src.
func (s *Scanner) Init(src string) {
func (s *Scanner) Init(text string) {
src := []rune(text)
s.source = src
s.sourcePos = 0
s.sourceSize = len(src)
Expand Down

0 comments on commit bc661e8

Please sign in to comment.