SPAM-LOW: Re: [Mono-dev] NUnit 2.2.6 Portability Bug

Charlie Poole charlie at nunit.com
Sat Jan 28 21:15:52 EST 2006


Hi Jonathan, 

> On Fri, 2006-01-27 at 12:25 -0800, Charlie Poole wrote:
> > I have some code that can be modified to replace the 
> functions I use, 
> > but before I re-invent the wheel, can anyone point to portable 
> > implementations of Windows PathCanonicalize and PathRelativePathTo? 
> > Better yet, does anyone want to contribute implementations? See 
> > PathUtils.cs for how we use these functions.
> 
> PathCanonicalize: System.IO.Path.GetFullPath() performs path 
> canonicalization.  At least Mono's version does...

I'll write a test. :-)
 
> PathRelativePathTo: this variation on your 
> PathUtils.RelativePath works for me (minimally tested):

This looks too simple to work, but I'll try it. ;-)

Seriously, it looks like it's gonna do the job. I'll write some tests to be
sure.

Thanks for the contribution,
Charlie
 
> 	public static string RelativePath (string from, string to)
> 	{
> 		string[] _from = from.Split 
> (Path.DirectorySeparatorChar);
> 		string[] _to   =   to.Split 
> (Path.DirectorySeparatorChar);
> 
> 		StringBuilder sb = new StringBuilder 
> (from.Length + to.Length);
> 
> 		int last_common, min = Math.Min (_from.Length, 
> _to.Length);
> 		for (last_common = 0; last_common < min;  
> ++last_common) {
> 			if (!_from [last_common].Equals (_to 
> [last_common]))
> 				break;
> 		}
> 		for (int i = last_common; i < _from.Length; ++i) {
> 			if (sb.Length > 0)
> 				sb.Append (Path.DirectorySeparatorChar);
> 			sb.Append ("..");
> 		}
> 		for (int i = last_common; i < _to.Length; ++i)
> 			sb.Append 
> (Path.DirectorySeparatorChar).Append (_to [i]);
> 
> 		return sb.ToString ();
> 	}
> 
>  - Jon
> 
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 






More information about the Mono-devel-list mailing list