Esempio n. 1
0
        public static bool TryResolvePath(string relativePath, out ReadableDargonNode node)
        {
            relativePath = relativePath.Replace('\\', '/');

             var currentNode = DumperGlobals.CurrentNode;
             while (relativePath.Length > 0) {
            if (relativePath[0] == '/') {
               currentNode = DumperGlobals.RootNode;
               relativePath = relativePath.Substring(1);
            } else {
               var delimiterIndex = relativePath.IndexOf('/');
               string breadcrumbName;
               if (delimiterIndex == -1) {
                  breadcrumbName = relativePath;
                  relativePath = "";
               } else {
                  breadcrumbName = relativePath.Substring(0, delimiterIndex);
                  relativePath = relativePath.Substring(delimiterIndex + 1);
               }

               if (breadcrumbName == ".") {
                  // do nothing
               } else if (breadcrumbName == "..") {
                  var parent = currentNode.Parent;
                  if (parent == null) {
                     Console.Error.WriteLine($"Parent of node {currentNode.Name} does not exist.");
                  } else {
                     currentNode = parent;
                  }
               } else {
                  ReadableDargonNode nextNode;
                  if (!currentNode.TryGetChild(breadcrumbName, out nextNode)) {
                     Console.Error.WriteLine($"Unable to find child {breadcrumbName}.");
                     node = null;
                     return false;
                  } else {
                     currentNode = nextNode;
                  }
               }
            }
             }
             node = currentNode;
             return true;
        }
Esempio n. 2
0
        public static bool TryResolvePath(string relativePath, out ReadableDargonNode node)
        {
            relativePath = relativePath.Replace('\\', '/');

            var currentNode = DumperGlobals.CurrentNode;

            while (relativePath.Length > 0)
            {
                if (relativePath[0] == '/')
                {
                    currentNode  = DumperGlobals.RootNode;
                    relativePath = relativePath.Substring(1);
                }
                else
                {
                    var    delimiterIndex = relativePath.IndexOf('/');
                    string breadcrumbName;
                    if (delimiterIndex == -1)
                    {
                        breadcrumbName = relativePath;
                        relativePath   = "";
                    }
                    else
                    {
                        breadcrumbName = relativePath.Substring(0, delimiterIndex);
                        relativePath   = relativePath.Substring(delimiterIndex + 1);
                    }

                    if (breadcrumbName == ".")
                    {
                        // do nothing
                    }
                    else if (breadcrumbName == "..")
                    {
                        var parent = currentNode.Parent;
                        if (parent == null)
                        {
                            Console.Error.WriteLine($"Parent of node {currentNode.Name} does not exist.");
                        }
                        else
                        {
                            currentNode = parent;
                        }
                    }
                    else
                    {
                        ReadableDargonNode nextNode;
                        if (!currentNode.TryGetChild(breadcrumbName, out nextNode))
                        {
                            Console.Error.WriteLine($"Unable to find child {breadcrumbName}.");
                            node = null;
                            return(false);
                        }
                        else
                        {
                            currentNode = nextNode;
                        }
                    }
                }
            }
            node = currentNode;
            return(true);
        }