fix bug that only first line has been converted from ascii to unicode

This commit is contained in:
Dom 2019-08-13 17:36:21 +02:00
parent 335f5f2ac5
commit 84bbbd8f9c
1 changed files with 8 additions and 2 deletions

10
bnn.go
View File

@ -135,6 +135,7 @@ func ReadBnnFile(path string) (Bnn, error) {
// ReadBnn Reads from reader and returns object with all containing information // ReadBnn Reads from reader and returns object with all containing information
func ReadBnn(r io.Reader) (Bnn, error) { func ReadBnn(r io.Reader) (Bnn, error) {
//dr := charmap.CodePage850.NewDecoder().Reader(r)
scanner := bufio.NewScanner(r) scanner := bufio.NewScanner(r)
var lines []string var lines []string
@ -143,14 +144,19 @@ func ReadBnn(r io.Reader) (Bnn, error) {
} }
var content Bnn var content Bnn
var encoding string
for i, line := range lines { for i, line := range lines {
var item Item 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 // Example file for ASCII was provided by Paxan
// Extended ASCII has been used -> ä 132 \u0084 // Extended ASCII has been used -> ä 132 \u0084
if strings.Split(line, ";")[2] == "0" { if encoding == "ascii" {
line, _ = charmap.CodePage850.NewDecoder().String(line) line, _ = charmap.CodePage850.NewDecoder().String(line)
} }