示例#1
0
        public Path GetParentPath(Path root)
        {
            var path = this;

            // normalize first
            path = path.NormalizeSlashes().TrimEndSlash();

            if (root != null)
            {
                root = root.NormalizeSlashes().TrimEndSlash();
                if (string.Equals(path, root, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(new Path(CorrectSlash, WrongSlash, string.Empty));
                }
            }

            int iLastSlash = path._rawPath.LastIndexOf(CorrectSlash);

            string newPath = root;

            if (iLastSlash > 0)
            {
                newPath = path._rawPath.Substring(0, iLastSlash);
            }
            else if (iLastSlash == 0)
            {
                newPath = new Path(CorrectSlash, WrongSlash, CorrectSlash);
            }

            Path resultPath = new Path(CorrectSlash, WrongSlash, newPath);

            return(resultPath.ApplyDriveSlash());
        }
示例#2
0
        public Path GetParentPath(Path root)
        {
            var path = this;

            path = path.NormalizeSlashes();
            path = path.TrimEndSlash();

            if (root != null)
            {
                if (string.Equals(path, root, StringComparison.CurrentCultureIgnoreCase))
                {
                    return new Path(CorrectSlash, WrongSlash, string.Empty);
                }
            }

            int iLastSlash = path._rawPath.LastIndexOf(CorrectSlash);

            string newPath = root;

            if (iLastSlash > 0)
            {
                newPath = path._rawPath.Substring(0, iLastSlash);
            }
            else if (iLastSlash == 0)
            {
                newPath = new Path(CorrectSlash, WrongSlash, CorrectSlash);
            }

            Path resultPath = new Path(CorrectSlash, WrongSlash, newPath);

            return resultPath.ApplyDriveSlash();
        }