Reko.Core.Services.FileSystemServiceImpl.MakeRelativePath C# (CSharp) Method

MakeRelativePath() public method

public MakeRelativePath ( string fromPath, string toPath ) : string
fromPath string
toPath string
return string
        public string MakeRelativePath(string fromPath, string toPath)
        {
            int iLastDir = -1;
            int i;
            for (i = 0; i < fromPath.Length && i < toPath.Length; ++i)
            {
                if (fromPath[i] != toPath[i])
                    break;
                if (fromPath[i] == this.sepChar)
                    iLastDir = i + 1;
            }
            var sb = new StringBuilder();
            if (iLastDir <= 1)
                return toPath;
            for (i = iLastDir; i < fromPath.Length; ++i)
            {
                if (fromPath[i] == this.sepChar)
                {
                    sb.Append("..");
                    sb.Append(sepChar);
                }
            }
            sb.Append(toPath.Substring(iLastDir));
            return sb.ToString();
        }

Usage Example

 public void FS_MakeRelative_1()
 {
     fs = new FileSystemServiceImpl('/');
     Assert.AreEqual("ax", fs.MakeRelativePath("/home/ox", "/home/ax"));
 }