mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
epubtree hide struc
This commit is contained in:
parent
402e450aca
commit
9da0887334
@ -207,7 +207,7 @@ func (e *ePub) getTree(images []*epubimage.Image, skip_files bool) string {
|
|||||||
c = c.Children[0]
|
c = c.Children[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.ToString("")
|
return c.WriteString("")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ePub) Write() error {
|
func (e *ePub) Write() error {
|
||||||
|
@ -5,39 +5,39 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Tree struct {
|
type tree struct {
|
||||||
Nodes map[string]*Node
|
Nodes map[string]*node
|
||||||
}
|
}
|
||||||
|
|
||||||
type Node struct {
|
type node struct {
|
||||||
Value string
|
Value string
|
||||||
Children []*Node
|
Children []*node
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Tree {
|
func New() *tree {
|
||||||
return &Tree{map[string]*Node{
|
return &tree{map[string]*node{
|
||||||
".": {".", []*Node{}},
|
".": {".", []*node{}},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Tree) Root() *Node {
|
func (n *tree) Root() *node {
|
||||||
return n.Nodes["."]
|
return n.Nodes["."]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Tree) Add(filename string) {
|
func (n *tree) Add(filename string) {
|
||||||
cn := n.Root()
|
cn := n.Root()
|
||||||
cp := ""
|
cp := ""
|
||||||
for _, p := range strings.Split(filepath.Clean(filename), string(filepath.Separator)) {
|
for _, p := range strings.Split(filepath.Clean(filename), string(filepath.Separator)) {
|
||||||
cp = filepath.Join(cp, p)
|
cp = filepath.Join(cp, p)
|
||||||
if _, ok := n.Nodes[cp]; !ok {
|
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.Children = append(cn.Children, n.Nodes[cp])
|
||||||
}
|
}
|
||||||
cn = n.Nodes[cp]
|
cn = n.Nodes[cp]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) ToString(indent string) string {
|
func (n *node) WriteString(indent string) string {
|
||||||
r := strings.Builder{}
|
r := strings.Builder{}
|
||||||
if indent != "" {
|
if indent != "" {
|
||||||
r.WriteString(indent)
|
r.WriteString(indent)
|
||||||
@ -47,7 +47,7 @@ func (n *Node) ToString(indent string) string {
|
|||||||
}
|
}
|
||||||
indent += " "
|
indent += " "
|
||||||
for _, c := range n.Children {
|
for _, c := range n.Children {
|
||||||
r.WriteString(c.ToString(indent))
|
r.WriteString(c.WriteString(indent))
|
||||||
}
|
}
|
||||||
return r.String()
|
return r.String()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user