From a32f5b55f9103cbe5a01421be2a9b1ed03b3ba6e Mon Sep 17 00:00:00 2001 From: eson Date: Fri, 18 Sep 2020 19:19:56 +0800 Subject: [PATCH] todo --- main_test.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/main_test.go b/main_test.go index 2480f24..5beb534 100644 --- a/main_test.go +++ b/main_test.go @@ -36,15 +36,26 @@ type Node struct { // return string(path) // } -func xPath(spath string) string { - var path []byte = make([]byte, len(spath)) +func xPath(spath string) { + var path []byte = make([]byte, len(spath)+1) copy(path, spath) - for i := 0; i < len(path); i++ { + root := &Node{} + cur := root + + for i := 0; i < len(spath); i++ { c := path[i] if c == '/' { + if path[i+1] == '/' { + cur.Type = TypeAllChildren + } else { + cur.Type = TypeChild + } + cur.Next = &Node{Next: cur} + cur = cur.Next } + cur.Name = append(cur.Name, c) } }