epubtree hide struc

This commit is contained in:
Celogeek 2023-04-25 10:34:56 +02:00
parent 402e450aca
commit 9da0887334
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
2 changed files with 13 additions and 13 deletions

View File

@ -207,7 +207,7 @@ func (e *ePub) getTree(images []*epubimage.Image, skip_files bool) string {
c = c.Children[0]
}
return c.ToString("")
return c.WriteString("")
}
func (e *ePub) Write() error {

View File

@ -5,39 +5,39 @@ import (
"strings"
)
type Tree struct {
Nodes map[string]*Node
type tree struct {
Nodes map[string]*node
}
type Node struct {
type node struct {
Value string
Children []*Node
Children []*node
}
func New() *Tree {
return &Tree{map[string]*Node{
".": {".", []*Node{}},
func New() *tree {
return &tree{map[string]*node{
".": {".", []*node{}},
}}
}
func (n *Tree) Root() *Node {
func (n *tree) Root() *node {
return n.Nodes["."]
}
func (n *Tree) Add(filename string) {
func (n *tree) Add(filename string) {
cn := n.Root()
cp := ""
for _, p := range strings.Split(filepath.Clean(filename), string(filepath.Separator)) {
cp = filepath.Join(cp, p)
if _, ok := n.Nodes[cp]; !ok {
n.Nodes[cp] = &Node{Value: p, Children: []*Node{}}
n.Nodes[cp] = &node{Value: p, Children: []*node{}}
cn.Children = append(cn.Children, n.Nodes[cp])
}
cn = n.Nodes[cp]
}
}
func (n *Node) ToString(indent string) string {
func (n *node) WriteString(indent string) string {
r := strings.Builder{}
if indent != "" {
r.WriteString(indent)
@ -47,7 +47,7 @@ func (n *Node) ToString(indent string) string {
}
indent += " "
for _, c := range n.Children {
r.WriteString(c.ToString(indent))
r.WriteString(c.WriteString(indent))
}
return r.String()
}