Esempio n. 1
0
        public void Test_PrefixDosDevice_UNC1()
        {
            var src  = @"\\.\UNC";
            var scan = new FilepathScanner(src);

            Assert.IsTrue(DosDeviceUnc.TryParse(scan, out var prefix));
        }
Esempio n. 2
0
        public static bool TryParse(FilepathScanner aScan, out DosDevice?oResult)
        {
            oResult = null;

            if (!aScan.Skip(PREFIX_PATTERN, out var match))
            {
                return(false);
            }

            oResult          = new DosDevice();
            oResult.SignChar = match.Groups[1].Value;

            if (aScan.Skip(UNC_PATTERN, out var asUnc))
            {
                // \\.\UNC\serever\share-name\....
                oResult.IsUnc  = true;
                oResult.Server = asUnc.Groups[2].Value;
                oResult.Share  = asUnc.Groups[4].Value;
                oResult.Volume = oResult.Server + asUnc.Groups[3].Value.Replace('/', System.IO.Path.DirectorySeparatorChar);
            }
            else if (aScan.Skip(VOLUME_PATTERN, out var volumePart))
            {
                // \\.\some-volume\...
                oResult.Volume = volumePart.Groups[1].Value;
            }

            return(true);
        }
Esempio n. 3
0
 static IPathPrefix _ParsePrefix(FilepathScanner aScan)
 {
     if (!PathLogics.SeemsWin32FileSystem)
     {
         return(PathPrefix.None.Instance);
     }
     else if (PathPrefix.Dos.TryParse(aScan, out var traDos))
     {
         return(traDos !);
     }
     else if (PathPrefix.DosDeviceUnc.TryParse(aScan, out var pxDosDecUnc))
     {
         return(pxDosDecUnc !);
     }
     else if (PathPrefix.DosDeviceDrive.TryParse(aScan, out var pxDosDevDrive))
     {
         return(pxDosDevDrive !);
     }
     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.None.Instance);
     }
 }
Esempio n. 4
0
        public void Test_PrefixDosDevice_1()
        {
            var src  = @"\\.\";
            var scan = new FilepathScanner(src);

            Assert.IsTrue(DosDevice.TryParse(scan, out var prefix));
            Assert.IsFalse(prefix !.IsUnc);
        }
Esempio n. 5
0
        public void Test_PrefixDosDevice_Normal2()
        {
            var src  = @"\\.\Volume{xxx-xxx-xxx}\dir\file.txt";
            var scan = new FilepathScanner(src);

            Assert.IsTrue(DosDevice.TryParse(scan, out var prefix));
            Assert.AreEqual(@"Volume{xxx-xxx-xxx}", prefix !.Volume);
        }
Esempio n. 6
0
        public void Test_PrefixJustUnc_2()
        {
            var src  = @"\\server\share-name\dir\file.txt";
            var scan = new FilepathScanner(src);

            Assert.IsTrue(Unc.TryParse(scan, out var prefix));
            Assert.AreEqual("server", prefix !.Server);
            Assert.AreEqual("share-name", prefix !.Share);
        }
Esempio n. 7
0
        public void Test_PrefixJustUnc_1()
        {
            var src  = @"\\server\C$";
            var scan = new FilepathScanner(src);

            Assert.IsTrue(Unc.TryParse(scan, out var prefix));
            Assert.AreEqual("server", prefix !.Server);
            Assert.AreEqual("C$", prefix !.Share);
        }
Esempio n. 8
0
        public void Test_PrefixDosDevice_Normal1()
        {
            var src  = @"\\.\C:\dir\file.txt";
            var scan = new FilepathScanner(src);

            Assert.IsTrue(DosDevice.TryParse(scan, out var prefix));
            Assert.IsFalse(prefix !.IsUnc);
            Assert.AreEqual(@"C:", prefix !.Volume);
        }
Esempio n. 9
0
        static IEnumerable <string> _ParsePath(FilepathScanner aScan)
        {
            while (aScan.Skip(ItemPattern, out var match))
            {
                yield return(match.Groups[1].Value);

                aScan.Skip(SeparatingPattern);
            }
        }
Esempio n. 10
0
        public void Test_PrefixDosDevice_UNC3()
        {
            var src  = @"\\?\UNC\127.0.0.1\share-name";
            var scan = new FilepathScanner(src);

            Assert.IsTrue(DosDeviceUnc.TryParse(scan, out var prefix));
            Assert.AreEqual(@"127.0.0.1", prefix !.Server);
            Assert.AreEqual(@"share-name", prefix !.Share);
            Assert.AreEqual(@"127.0.0.1\share-name", prefix !.Volume);
        }
Esempio n. 11
0
        public void Test_PrefixDosDevice_UNC2()
        {
            var src  = @"\\.\UNC\127.0.0.1";
            var scan = new FilepathScanner(src);

            Assert.IsTrue(DosDeviceUnc.TryParse(scan, out var prefix));
            Assert.AreEqual(@"127.0.0.1", prefix !.Server);
            Assert.IsTrue(string.IsNullOrEmpty(prefix !.Share));
            Assert.AreEqual(@"127.0.0.1", prefix !.Volume);
        }
Esempio n. 12
0
        public void Test_PrefixDosDevice_Drive_1()
        {
            Action <string> test_ = srcStr =>
            {
                var scan = new FilepathScanner(srcStr);
                Assert.IsTrue(DosDeviceDrive.TryParse(scan, out var prefix));
            };

            test_(@"\\.\C:");
            test_(@"\\.\C:");
            test_(@"//?/C:");
            test_(@"//?/C:");
        }
Esempio n. 13
0
        public static bool TryParse(FilepathScanner aScan, out Unc?oResult)
        {
            oResult = null;

            if (!aScan.Skip(PREFIX_PATTERN, out var match))
            {
                return(false);
            }

            oResult        = new Unc();
            oResult.Server = match.Groups[1].Value;
            oResult.Share  = match.Groups[2].Value;
            return(true);
        }
Esempio n. 14
0
        /// <summary>
        /// <example>
        /// Traditional DOS path
        /// <code>
        /// var normal_abs  = Parse(@"C:\dir\file.txt");
        /// var normal_rel  = Parse(@"relative\dir\and\file.txt");
        /// var simple_abs  = Parse(@"\");
        /// var simple_abs2 = Parse(@"C:\");
        /// var drive_rel   = Parse(@"C:");  // specifies a drive, but relative
        /// var drive_rel_2 = Parse(@"D:drive-and-relative\dir\file");
        /// </code>
        ///
        /// DOS Device path
        /// <code>Parse(@"\\?\volume/dir/more-dir/.git");</code>
        ///
        /// UNC path
        /// <code>Parse(@"\\server\share-name\dir\file");</code>
        ///
        /// UNIX
        /// <code>
        ///   Parse("/usr/local/bin");
        ///   Parse("/");  // root
        /// </code>
        /// </example>
        /// </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.IsAbsolute = scan.Skip(SeparatingPattern);
            self.Items      = new(_ParsePath(scan));
            return(self);
        }
Esempio n. 15
0
        public static bool TryParse(FilepathScanner aScan, out Dos?oResult)
        {
            oResult = null;

            if (!aScan.Skip(PREFIX_PATTERN, out var match))
            {
                return(false);
            }

            oResult = new Dos
            {
                Drive       = match.Value,
                DriveLetter = match.Groups[1].Value,
            };

            return(true);
        }
Esempio n. 16
0
        public void Test_PrefixOfDosDevice_Regex()
        {
            {
                var src1 = FilepathScanner._Prepare(@"\\.\foo");
                var m1   = DosDevice.PREFIX_PATTERN.Match(src1);
                Assert.IsTrue(m1.Success);
                Assert.AreEqual(@".", m1.Groups[1].Value);
                Assert.AreEqual(@"/foo", src1.Substring(m1.Length));
            }

            {
                var src2 = FilepathScanner._Prepare(@"\\?\foo");
                var m2   = DosDevice.PREFIX_PATTERN.Match(src2);
                Assert.IsTrue(m2.Success);
                Assert.AreEqual(@"?", m2.Groups[1].Value);
                Assert.AreEqual(@"/foo", src2.Substring(m2.Length));
            }
        }