From 84bbbd8f9ce2919cfaaac634edd4356e6ece25d5 Mon Sep 17 00:00:00 2001 From: Dom Date: Tue, 13 Aug 2019 17:36:21 +0200 Subject: [PATCH] fix bug that only first line has been converted from ascii to unicode --- bnn.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bnn.go b/bnn.go index aaa4bf1..2359c5c 100755 --- a/bnn.go +++ b/bnn.go @@ -135,6 +135,7 @@ func ReadBnnFile(path string) (Bnn, error) { // ReadBnn Reads from reader and returns object with all containing information func ReadBnn(r io.Reader) (Bnn, error) { + //dr := charmap.CodePage850.NewDecoder().Reader(r) scanner := bufio.NewScanner(r) var lines []string @@ -143,14 +144,19 @@ func ReadBnn(r io.Reader) (Bnn, error) { } var content Bnn + var encoding string for i, line := range lines { var item Item - // Encoding ASCII + // How to decode file? Use header info for encoding information. + if i == 0 && strings.Split(line, ";")[2] == "0" { + encoding = "ascii" + } + // Example file for ASCII was provided by Paxan // Extended ASCII has been used -> รค 132 \u0084 - if strings.Split(line, ";")[2] == "0" { + if encoding == "ascii" { line, _ = charmap.CodePage850.NewDecoder().String(line) }