UnityEngine.NUnit.Framework.Constraints.PathConstraint.Canonicalize C# (CSharp) Method

Canonicalize() protected static method

Transform the provided path to its canonical form so that it may be more easily be compared with other paths.
protected static Canonicalize ( string path ) : string
path string The original path
return string
        protected static string Canonicalize(string path)
        {
            if (Path.DirectorySeparatorChar != Path.AltDirectorySeparatorChar)
                path = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
            string leadingSeparators = "";
            foreach (char c in path)
            {
                if (c == WindowsDirectorySeparatorChar || c == NonWindowsDirectorySeparatorChar)
                {
                    leadingSeparators += Path.DirectorySeparatorChar;
                }
                else break;
            }

#if (CLR_2_0x || CLR_4_0) && !NETCF
            string[] parts = path.Split(DirectorySeparatorChars, StringSplitOptions.RemoveEmptyEntries);
#else
            string[] parts = path.Split(DirectorySeparatorChars);
#endif
            int count = 0;
            bool shifting = false;
            foreach (string part in parts)
            {
                switch (part)
                {
                    case "":
                    case ".":
                        shifting = true;
                        break;

                    case "..":
                        shifting = true;
                        if (count > 0)
                            --count;
                        break;

                    default:
                        if (shifting)
                            parts[count] = part;
                        ++count;
                        break;
                }
            }

            return leadingSeparators + String.Join(Path.DirectorySeparatorChar.ToString(), parts, 0, count);
        }