Initial commit
I can parse some of the data files, and extract individual frames from .obj files. I can't yet convert those frames into something viewable.
This commit is contained in:
52
internal/data/accounting.go
Normal file
52
internal/data/accounting.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Comments are `//`, start of line only, for accounting
|
||||
var (
|
||||
comment = []byte("//")
|
||||
)
|
||||
|
||||
type Accounting map[string]string
|
||||
|
||||
func LoadAccounting(filename string) (Accounting, error) {
|
||||
scanLines, err := fileToScanner(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := make(Accounting)
|
||||
|
||||
for scanLines.Scan() {
|
||||
if err := parse(out, scanLines.Bytes()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanLines.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func parse(into Accounting, line []byte) error {
|
||||
if len(line) == 0 || bytes.Equal(line[0:2], comment) {
|
||||
return nil
|
||||
}
|
||||
|
||||
idx := bytes.Index(line, []byte("="))
|
||||
key := string(line[0:idx])
|
||||
value := string(bytes.Trim(line[idx+1:len(line)], "\t\r\n"))
|
||||
|
||||
if _, ok := into[key]; ok {
|
||||
return errors.New("Duplicate key: " + key)
|
||||
}
|
||||
|
||||
into[key] = value
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user