-
Notifications
You must be signed in to change notification settings - Fork 1
/
exported.go
46 lines (38 loc) · 875 Bytes
/
exported.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package kdlgo
import (
"bufio"
"os"
"strings"
)
func ParseFile(fullfilepath string) (KDLObjects, error) {
var t KDLObjects
f, err := os.Open(fullfilepath)
if err != nil {
return t, err
}
r := bufio.NewReader(f)
return ParseReader(r)
}
func ParseString(toParse string) (KDLObjects, error) {
return ParseReader(bufio.NewReader(strings.NewReader(toParse)))
}
func ParseReader(reader *bufio.Reader) (KDLObjects, error) {
r := newKDLReader(reader)
return parseObjects(r, false, "")
}
func ConvertToDocument(objs []KDLObject) (KDLDocument, error) {
var key string
var vals []KDLValue
var doc KDLDocument
if len(objs) < 1 {
return doc, emptyArrayErr()
}
key = objs[0].GetKey()
for _, obj := range objs {
if obj.GetKey() != key {
return doc, differentKeysErr()
}
vals = append(vals, obj.GetValue())
}
return NewKDLDocument(key, vals), nil
}