protected static IEnumerable <PathSegment> GetSegments(string value) { int startIx = 0; while (startIx < value.Length && char.IsWhiteSpace(value[startIx])) { startIx++; } int endIx = value.Length - 1; while (endIx >= 0 && char.IsWhiteSpace(value[endIx])) { endIx--; } for (; startIx < endIx; startIx++) { if (char.IsWhiteSpace(value[startIx])) { var segment = value.Substring(0, startIx); var hasExtension = PathResolveHelper.HasWhatLookLikeExtesion(segment); yield return(new PathSegment { Path = segment, HasExtension = PathResolveHelper.HasWhatLookLikeExtesion(segment), Index = startIx - 1 }); if (hasExtension) { yield break; } } } yield return(new PathSegment { Path = value, HasExtension = PathResolveHelper.HasWhatLookLikeExtesion(value), Final = true, Index = value.Length - 1 }); }
private int ResolveQuoted(string value, string workingDir, out string fullCommandPath) { fullCommandPath = null; if (value.Length == 1) { return(-1); } var closeIx = value.IndexOf('"', 1); if (closeIx == -1) { return(-1); } value = value.Substring(1, closeIx - 1); if (string.IsNullOrEmpty(value)) { return(-1); } if (PathResolveHelper.IsAbsolutePath(value)) { var hasExtesion = PathResolveHelper.HasWhatLookLikeExtesion(value); if (PathResolveHelper.TryResolveAbsolutePath(value, hasExtesion, true, out fullCommandPath)) { return(closeIx); } } else { if (ResolveRelativeQuoted(value, workingDir, out fullCommandPath)) { return(closeIx); } } return(-1); }
private static bool TryResolveRelative(string path, string workingDir, out string fullPath) { bool hasExt = PathResolveHelper.HasWhatLookLikeExtesion(path); var self = Enumerable.Repeat(string.Empty, 1); var extesions = hasExt ? self : PathResolveHelper.PathExt.Concat(self); foreach (var extension in extesions) { if (TrySeachInPath(workingDir, path, extension, out fullPath)) { return(true); } if (TrySeachInPath(null, path, extension, out fullPath)) { return(true); } } fullPath = null; return(false); }