Skip to content

Commit

Permalink
fix readstring unicode reading
Browse files Browse the repository at this point in the history
  • Loading branch information
pektezol committed Sep 16, 2023
1 parent 3e30e44 commit 46e08f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions bitreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,18 @@ func (reader *Reader) ReadBytes(bytes uint64) (uint64, error) {
//
// Returns an error if there are no remaining bits.
func (reader *Reader) ReadString() (string, error) {
var out string
var out []byte
for {
value, err := reader.ReadBytes(1)
if err != nil {
return out, err
return string(out), err
}
if value == 0 {
break
}
out += string(rune(value))
out = append(out, byte(value))
}
return out, nil
return string(out), nil
}

// ReadStringLength is a function that reads every byte
Expand All @@ -389,20 +389,20 @@ func (reader *Reader) ReadString() (string, error) {
//
// Returns an error if there are no remaining bits.
func (reader *Reader) ReadStringLength(length uint64) (string, error) {
var out string
var out []byte
var i uint64
for i = 0; i < length; i++ {
value, err := reader.ReadBytes(1)
if err != nil {
return out, err
return string(out), err
}
if value == 0 {
reader.SkipBytes(length - 1 - i)
break
}
out += string(rune(value))
out = append(out, byte(value))
}
return out, nil
return string(out), nil
}

// ReadBitsToSlice is a function that reads the specified amount of bits
Expand Down
22 changes: 11 additions & 11 deletions bitreader_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// BitReader is a simple bit reader with big/little-endian support for golang.
// %83.2 coerage
// %83.6 coerage
package bitreader

import (
Expand Down Expand Up @@ -616,7 +616,7 @@ func TestReader_TryReadFloat64(t *testing.T) {

func TestReader_TryReadBits(t *testing.T) {
type args struct {
bits int
bits uint64
}
tests := []struct {
name string
Expand Down Expand Up @@ -662,7 +662,7 @@ func TestReader_TryReadBits(t *testing.T) {

func TestReader_TryReadBytes(t *testing.T) {
type args struct {
bytes int
bytes uint64
}
tests := []struct {
name string
Expand Down Expand Up @@ -744,7 +744,7 @@ func TestReader_TryReadString(t *testing.T) {

func TestReader_TryReadStringLength(t *testing.T) {
type args struct {
length int
length uint64
}
tests := []struct {
name string
Expand Down Expand Up @@ -803,7 +803,7 @@ func TestReader_TryReadStringLength(t *testing.T) {

func TestReader_TryReadBitsToSlice(t *testing.T) {
type args struct {
bits int
bits uint64
}
tests := []struct {
name string
Expand Down Expand Up @@ -875,7 +875,7 @@ func TestReader_TryReadBitsToSlice(t *testing.T) {

func TestReader_TryReadBytesToSlice(t *testing.T) {
type args struct {
bytes int
bytes uint64
}
tests := []struct {
name string
Expand Down Expand Up @@ -1012,7 +1012,7 @@ func TestReader_ReadBool(t *testing.T) {

func TestReader_ReadBits(t *testing.T) {
type args struct {
bits int
bits uint64
}
tests := []struct {
name string
Expand Down Expand Up @@ -1064,7 +1064,7 @@ func TestReader_ReadBits(t *testing.T) {

func TestReader_ReadBytes(t *testing.T) {
type args struct {
bytes int
bytes uint64
}
tests := []struct {
name string
Expand Down Expand Up @@ -1158,7 +1158,7 @@ func TestReader_ReadString(t *testing.T) {

func TestReader_ReadStringLength(t *testing.T) {
type args struct {
length int
length uint64
}
tests := []struct {
name string
Expand Down Expand Up @@ -1223,7 +1223,7 @@ func TestReader_ReadStringLength(t *testing.T) {

func TestReader_ReadBitsToSlice(t *testing.T) {
type args struct {
bits int
bits uint64
}
tests := []struct {
name string
Expand Down Expand Up @@ -1301,7 +1301,7 @@ func TestReader_ReadBitsToSlice(t *testing.T) {

func TestReader_ReadBytesToSlice(t *testing.T) {
type args struct {
bytes int
bytes uint64
}
tests := []struct {
name string
Expand Down

0 comments on commit 46e08f3

Please sign in to comment.