-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutil.go
64 lines (54 loc) · 1.55 KB
/
util.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package fb2
import (
"io"
prototype "github.com/centrypoint/fb2/prototype"
"golang.org/x/text/encoding/charmap"
)
// get xlink from enclosed tag image
func parseImage(data []byte) string {
result := ""
quoteOpened := false
_loop:
for _, v := range data {
if quoteOpened {
if v == '"' {
break _loop
}
result += string(v)
} else {
if v == '"' {
quoteOpened = true
}
}
}
return result
}
// decode windows-1251
func decodeWin1251(i io.Reader) (r io.Reader) {
decoder := charmap.Windows1251.NewDecoder()
r = decoder.Reader(i)
return
}
// ToPB converts fb2 to protobuf fb2
func ToPB(target FB2) prototype.PFB2 {
var result = NewPFB2()
result.Description.TitleInfo.Annotation = target.Description.TitleInfo.Annotation
for i, v := range target.Description.TitleInfo.Author {
result.Description.TitleInfo.Author[i].FirstName = v.FirstName
result.Description.TitleInfo.Author[i].MiddleName = v.MiddleName
result.Description.TitleInfo.Author[i].LastName = v.LastName
result.Description.TitleInfo.Author[i].Email = v.Email
result.Description.TitleInfo.Author[i].HomePage = v.HomePage
result.Description.TitleInfo.Author[i].Nickname = v.Nickname
}
result.Description.TitleInfo.Annotation = target.Description.TitleInfo.Annotation
result.Description.TitleInfo.Annotation = target.Description.TitleInfo.Annotation
result.ID = target.ID
return result
}
func NewPFB2() prototype.PFB2 {
var result prototype.PFB2
result.Description = new(prototype.Description)
result.Description.TitleInfo = new(prototype.TitleInfo)
return result
}