From 90f9bd2d5b100f7a0339c0819b9a951a55b782a3 Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Fri, 7 Jan 2022 02:04:30 +0500 Subject: [PATCH] :label: Added Delim type --- tree.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tree.go b/tree.go index e916294..e1e88c2 100644 --- a/tree.go +++ b/tree.go @@ -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.