From 46e08f3bcb88ddfb2984ef67fce9e9ff0abafb8e Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Sat, 16 Sep 2023 13:54:51 +0300 Subject: fix readstring unicode reading --- bitreader.go | 16 ++++++++-------- bitreader_test.go | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bitreader.go b/bitreader.go index e50f433..6b88709 100644 --- a/bitreader.go +++ b/bitreader.go @@ -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 @@ -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 diff --git a/bitreader_test.go b/bitreader_test.go index acd980e..588590a 100644 --- a/bitreader_test.go +++ b/bitreader_test.go @@ -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 ( @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 -- cgit v1.2.3