X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FMicrosoft.Build.Engine%2FMicrosoft.Build.BuildEngine%2FUtilities.cs;h=579785db639fee097428f17babd5b7c9607352c5;hb=2332d6ff00c77598def60262d6c620b4e340db9c;hp=c92e14fb1cc488bbe4f3c335dbf80324fd32fd6c;hpb=0443306d611d0830e27327e1f0a3ef3457dfa535;p=mono.git diff --git a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Utilities.cs b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Utilities.cs index c92e14fb1cc..579785db639 100644 --- a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Utilities.cs +++ b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Utilities.cs @@ -3,8 +3,10 @@ // // Author: // Marek Sieradzki (marek.sieradzki@gmail.com) +// Lluis Sanchez Gual // // (C) 2005 Marek Sieradzki +// Copyright (c) 2008 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -29,6 +31,7 @@ using System; using System.Collections; +using System.IO; using System.Text; namespace Microsoft.Build.BuildEngine { @@ -56,15 +59,90 @@ namespace Microsoft.Build.BuildEngine { StringBuilder sb = new StringBuilder (); foreach (char c in unescapedExpression) { - if (charsToEscape.Contains (c)) { + if (charsToEscape.Contains (c)) sb.AppendFormat ("%{0:x2}", (int) c); - } else + else sb.Append (c); } return sb.ToString (); } + + // FIXME: add tests for this + internal static string Unescape (string escapedExpression) + { + StringBuilder sb = new StringBuilder (); + + int i = 0; + while (i < escapedExpression.Length) { + sb.Append (Uri.HexUnescape (escapedExpression, ref i)); + } + + return sb.ToString (); + } + + internal static string FromMSBuildPath (string relPath) + { + if (relPath == null || relPath.Length == 0) + return null; + + bool is_windows = Path.DirectorySeparatorChar == '\\'; + string path = relPath; + if (!is_windows) + path = path.Replace ("\\", "/"); + + // a path with drive letter is invalid/unusable on non-windows + if (!is_windows && char.IsLetter (path [0]) && path.Length > 1 && path[1] == ':') + return null; + + if (System.IO.File.Exists (path)){ + return Path.GetFullPath (path); + } + + if (Path.IsPathRooted (path)) { + + // Windows paths are case-insensitive. When mapping an absolute path + // we can try to find the correct case for the path. + + string[] names = path.Substring (1).Split ('/'); + string part = "/"; + + for (int n=0; n