示例#1
0
        static IEnumerable <string> _ParsePath(FilepathScanner aScan)
        {
            while (aScan.Skip(ITEM_PATTERN, out var match))
            {
                yield return(match.Groups[1].Value);

                aScan.Skip(SEPARATING_PATTERN);
            }
        }
示例#2
0
        /// <summary>
        /// Traditional DOS path
        ///   Parse(@"C:\dir\file.txt");
        ///   Parse(@"relative\dir\and\file.txt");
        ///   Parse(@"\");  // root
        ///   Parse(@"C:\");  // drive and root
        ///   Parse(@"C:");  // specifies a drive, but relative
        ///   Parse(@"D:drive-and-relative\dir\file");
        ///
        /// DOS Device path
        ///   Parse(@"\\?\volume/dir/more-dir/.git");
        ///
        /// UNC path
        ///   Parse(@"\\server\share-name\dir\file");
        ///
        /// UNIX
        ///   Parse("/usr/local/bin");
        ///   Parse("/");  // root
        /// </summary>
        /// <param name="aInput"></param>
        /// <returns></returns>
        public static Filepath Parse(string?aInput)
        {
            if (string.IsNullOrEmpty(aInput))
            {
                return(Empty);
            }

            var scan = new FilepathScanner(aInput ?? "");

            var self = new Filepath();

            self.Prefix   = _ParsePrefix(scan);
            self.Absolute = scan.Skip(SEPARATING_PATTERN);
            self.Items    = _ParsePath(scan).ToArray();
            return(self);
        }
示例#3
0
 static IPathPrefix _ParsePrefix(FilepathScanner aScan)
 {
     if (PathPrefix.Dos.TryParse(aScan, out var traDos))
     {
         return(traDos !);
     }
     else if (PathPrefix.DosDevice.TryParse(aScan, out var pxDosDev))
     {
         return(pxDosDev !);
     }
     else if (PathPrefix.Unc.TryParse(aScan, out var justUnc))
     {
         return(justUnc !);
     }
     else
     {
         return(PathPrefix.Empty.STATIC);
     }
 }