🏷️ Added Delim type

This commit is contained in:
Maxim Lebedev 2022-01-07 02:04:30 +05:00
parent 2d20c56224
commit 90f9bd2d5b
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 17 additions and 8 deletions

25
tree.go
View File

@ -6,25 +6,30 @@ import (
"strings"
)
// Node represent a single data structure.
type Node struct {
Parent *Node
Children []*Node
Value string
}
type (
// Node represent a single data structure.
Node struct {
Parent *Node
Children []*Node
Value string
}
// Delim is a delimiter between words (cells) in nodes (lines).
Delim rune
)
const (
// nodeBreakSymbol delimits nodes (lines).
nodeBreakSymbol rune = '\n'
// wordBreakSymbol delimits words (cells).
wordBreakSymbol rune = ' '
wordBreakSymbol Delim = ' '
// edgeSymbol is used to indicate the parent/child relationship between
// nodes.
//
// TODO(toby3d): allow clients to change this to '\t' for example.
edgeSymbol rune = wordBreakSymbol
edgeSymbol rune = ' '
)
// Parse parses the data into a Tree Notation nodes.
@ -95,6 +100,10 @@ func (n Node) GoString() (result string) {
return result
}
func (d Delim) String() string {
return string(d)
}
// lenIndent count egdeSymbol prefixes in line.
//
// Returns 0 if line starts from any word character.