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) }