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); }
static IEnumerable <string> _ParsePath(FilepathScanner aScan) { while (aScan.Skip(ItemPattern, out var match)) { yield return(match.Groups[1].Value); aScan.Skip(SeparatingPattern); } }
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); }
/// <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); }
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); }