[hyena] Paths: bring some path normalization operations between platforms



commit 01dd7306c8a1949c7617bae3c85bfbff410c3a75
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Sun Nov 11 21:22:37 2012 +0000

    Paths: bring some path normalization operations between platforms
    
    These operations are being used in Banshee's playlist code currently,
    but it makes more sense to encapsulate them as functions and leave them
    in the Hyena.Paths namespace, in a similar way as Paths.MakePathRelative()
    which is also used in the same class.

 Hyena/Hyena/Paths.cs |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/Hyena/Hyena/Paths.cs b/Hyena/Hyena/Paths.cs
index 5ead587..c2368dd 100644
--- a/Hyena/Hyena/Paths.cs
+++ b/Hyena/Hyena/Paths.cs
@@ -38,6 +38,12 @@ namespace Hyena
         public const char UnixSeparator = ':';
         public const char DosSeparator = ';';
 
+        public static class Folder
+        {
+            public const char UnixSeparator = '/';
+            public const char DosSeparator = '\\';
+        }
+
         public static string GetTempFileName (string dir)
         {
             return GetTempFileName (dir, null);
@@ -163,6 +169,19 @@ namespace Hyena
             return relativePath.ToString ();
         }
 
+        public static string NormalizeToDos (string path)
+        {
+            return path.Replace (Folder.UnixSeparator, Folder.DosSeparator);
+        }
+
+        public static string NormalizeToUnix (string path)
+        {
+            if (!path.Contains (Folder.UnixSeparator.ToString ()) && path.Contains (Folder.DosSeparator.ToString ())) {
+                return path.Replace (Folder.DosSeparator, Folder.UnixSeparator);
+            }
+            return path;
+        }
+
         public static string ApplicationData {
             get; private set;
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]