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
47
48
49
50
51
52
|
package bible
import "github.com/lukaszkasprzak/lectio/internal/ini"
// CorpusMeta is the sidecar metadata for a bible corpus (<code>.ini).
// Autoselect (default true) governs whether the corpus may be picked by the
// reading resolver's language auto-match; a corpus with Autoselect=false stays
// reachable only via an explicit reading_version or --ref (e.g. the built-in
// wuj, which is incomplete). See docs national-bibles design.
type CorpusMeta struct {
Code, Lang, Name, PsalmSystem, Sigla string
Autoselect bool
}
// parseCorpusMeta reads a section-less sidecar. ini.Parse returns
// []ini.Section{Name, Pairs}; keys before any [section] land in the section
// whose Name == "" (verified against internal/ini).
func parseCorpusMeta(code string, data []byte) CorpusMeta {
m := CorpusMeta{Code: code, Autoselect: true} // absent autoselect => true
secs, err := ini.Parse(data)
if err != nil {
return m
}
for _, s := range secs {
if s.Name != "" {
continue
}
for _, p := range s.Pairs {
switch p.Key {
case "lang":
m.Lang = p.Val
case "name":
m.Name = p.Val
case "psalm_system":
m.PsalmSystem = p.Val
case "sigla":
m.Sigla = p.Val
case "autoselect":
m.Autoselect = p.Val != "false"
}
}
}
return m
}
func embeddedCorpusMeta(code string) (CorpusMeta, bool) {
data, ok := embReadCorpus(code + ".ini")
if !ok {
return CorpusMeta{}, false
}
return parseCorpusMeta(code, data), true
}
|