Handle fault messages in duplex callback channel.
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / Utilities.cs
index cb31b2ed6047e4a885ad6593391088d461f76a98..235dd2eda238838aa2fc84a6c64b2fdfe7570e7c 100644 (file)
@@ -4,6 +4,7 @@
 // Author:
 //   Marek Sieradzki (marek.sieradzki@gmail.com)
 //   Lluis Sanchez Gual <lluis@novell.com>
+//   Michael Hutchinson <mhutchinson@novell.com>
 //
 // (C) 2005 Marek Sieradzki
 // Copyright (c) 2008 Novell, Inc (http://www.novell.com)
 
 #if NET_2_0
 
-using System;
-using System.Collections;
-using System.IO;
-using System.Text;
+using Mono.XBuild.Utilities;
 
 namespace Microsoft.Build.BuildEngine {
        public static class Utilities {
-       
-               static Hashtable charsToEscape;
-       
-               static Utilities ()
-               {
-                       charsToEscape = new Hashtable ();
-                       
-                       charsToEscape.Add ('$', null);
-                       charsToEscape.Add ('%', null);
-                       charsToEscape.Add ('\'', null);
-                       charsToEscape.Add ('(', null);
-                       charsToEscape.Add (')', null);
-                       charsToEscape.Add ('*', null);
-                       charsToEscape.Add (';', null);
-                       charsToEscape.Add ('?', null);
-                       charsToEscape.Add ('@', null);
-               }
-       
+
                public static string Escape (string unescapedExpression)
                {
-                       StringBuilder sb = new StringBuilder ();
-                       
-                       foreach (char c in unescapedExpression) {
-                               if (charsToEscape.Contains (c))
-                                       sb.AppendFormat ("%{0:x2}", (int) c);
-                               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 ();
+                       return MSBuildUtils.Escape (unescapedExpression);
                }
 
                internal static string FromMSBuildPath (string relPath)
                {
-                       if (relPath == null || relPath.Length == 0)
-                               return null;
-
-                       string path = relPath;
-                       if (Path.DirectorySeparatorChar != '\\')
-                               path = path.Replace ("\\", "/");
-
-                       if (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<names.Length; n++) {
-                                       string[] entries;
-
-                                       if (names [n] == ".."){
-                                               if (part == "/")
-                                                       return ""; // Can go further back. It's not an existing file
-                                               part = Path.GetFullPath (part + "/..");
-                                               continue;
-                                       }
-
-                                       entries = Directory.GetFileSystemEntries (part);
-
-                                       string fpath = null;
-                                       foreach (string e in entries) {
-                                               if (string.Compare (Path.GetFileName (e), names[n], true) == 0) {
-                                                       fpath = e;
-                                                       break;
-                                               }
-                                       }
-                                       if (fpath == null) {
-                                               // Part of the path does not exist. Can't do any more checking.
-                                               part = Path.GetFullPath (part);
-                                               for (; n < names.Length; n++)
-                                                       part += "/" + names[n];
-                                               return part;
-                                       }
-
-                                       part = fpath;
-                               }
-                               return Path.GetFullPath (part);
-                       } else {
-                               return Path.GetFullPath (path);
-                       }
+                       return MSBuildUtils.FromMSBuildPath (relPath);
                }
        }