removed unused variables
[mono.git] / mcs / class / System / System / Uri.cs
index 4be752c0a394e7d626014346bea3a88783db82a7..1a0d51ec54f882ae40d1b486c578193dcfc4508b 100755 (executable)
 // (C) 2003 Ben Maurer
 // (C) 2003 Novell inc.
 //
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 using System.IO;
 using System.Net;
 using System.Runtime.Serialization;
 using System.Text;
 using System.Collections;
+using System.Globalization;
 
 // See RFC 2396 for more info on URI's.
 
@@ -86,7 +108,7 @@ namespace System
                }
 
                public Uri (string uriString, bool dontEscape) 
-               {                       
+               {
                        userEscaped = dontEscape;
                        source = uriString;
                        Parse ();
@@ -341,13 +363,19 @@ namespace System
                                } else {
                                        // support *nix and W32 styles
                                        if (path.Length > 1 && path [1] == ':')
-                                               cachedLocalPath = Unescape (path.Replace ('/', '\\'));
+                                               cachedLocalPath = Unescape (path.Replace (Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar));
 
+                                       // LAMESPEC: ok, now we cannot determine
+                                       // if such URI like "file://foo/bar" is
+                                       // Windows UNC or unix file path, so
+                                       // they should be handled differently.
                                        else if (System.IO.Path.DirectorySeparatorChar == '\\')
                                                cachedLocalPath = "\\\\" + Unescape (host + path.Replace ('/', '\\'));
-                                       else 
-                                               cachedLocalPath = "//" + Unescape (host + path);
+                                       else
+                                               cachedLocalPath = Unescape (path);
                                }
+                               if (cachedLocalPath == String.Empty)
+                                       cachedLocalPath = Path.DirectorySeparatorChar.ToString ();
                                return cachedLocalPath;
                        } 
                }
@@ -444,7 +472,7 @@ namespace System
                                return false;
                        for (int i = 0; i < 4; i++) {
                                try {
-                                       int d = Int32.Parse (captures [i]);
+                                       int d = Int32.Parse (captures [i], CultureInfo.InvariantCulture);
                                        if (d < 0 || d > 255)
                                                return false;
                                } catch (Exception) {
@@ -519,13 +547,14 @@ namespace System
                                        return false;
                                uri = new Uri (s);
                        }
-                       
-                       return ((this.scheme.ToLower () == uri.scheme.ToLower ()) &&
-                               (this.userinfo.ToLower () == uri.userinfo.ToLower ()) &&
-                               (this.host.ToLower () == uri.host.ToLower ()) &&
+
+                       CultureInfo inv = CultureInfo.InvariantCulture;
+                       return ((this.scheme.ToLower (inv) == uri.scheme.ToLower (inv)) &&
+                               (this.userinfo.ToLower (inv) == uri.userinfo.ToLower (inv)) &&
+                               (this.host.ToLower (inv) == uri.host.ToLower (inv)) &&
                                (this.port == uri.port) &&
                                (this.path == uri.path) &&
-                               (this.query.ToLower () == uri.query.ToLower ()));
+                               (this.query.ToLower (inv) == uri.query.ToLower (inv)));
                }               
                
                public override int GetHashCode () 
@@ -617,7 +646,6 @@ namespace System
 
                        int stage = 0;
                        int c = 0;
-                       byte [] bytes = new byte [6];
                        do {
                                if (((index + 3) > pattern.Length) ||
                                    (pattern [index] != '%') || 
@@ -834,7 +862,6 @@ namespace System
                        isUnc = true;
 
                        uriString = uriString.TrimStart (new char [] {'\\'});
-                       isUnc = true;
                        int pos = uriString.IndexOf ('\\');
                        if (pos > 0) {
                                path = uriString.Substring (pos);
@@ -870,20 +897,22 @@ namespace System
                        path = null;
 
                        if (uriString.StartsWith ("//")) {
-                               // kind of Unix UNC
                                uriString = uriString.TrimStart (new char [] {'/'});
-                               isUnc = true;
+                               // Now we don't regard //foo/bar as "foo" host.
+                               /* 
                                int pos = uriString.IndexOf ('/');
                                if (pos > 0) {
                                        path = '/' + uriString.Substring (pos + 1);
                                        host = uriString.Substring (0, pos);
-                               } else { // "//server"
+                               } else { // "///server"
                                        host = uriString;
                                        path = String.Empty;
                                }
+                               */
+                               path = '/' + uriString;
                        }
                        if (path == null)
-                               path = uriString; // FIXME: Should allow '\\' ?
+                               path = uriString;
                }
 
                // this parse method is as relaxed as possible about the format
@@ -928,7 +957,7 @@ namespace System
                        }
 
                        // scheme
-                       scheme = uriString.Substring (0, pos).ToLower ();
+                       scheme = uriString.Substring (0, pos).ToLower (CultureInfo.InvariantCulture);
                        // Check scheme name characters as specified in RFC2396.
                        if (!Char.IsLetter (scheme [0]))
                                        throw new UriFormatException ("URI scheme must start with alphabet character.");
@@ -1006,7 +1035,7 @@ namespace System
                                string portStr = uriString.Remove (0, pos + 1);
                                if (portStr.Length > 1 && portStr [portStr.Length - 1] != ']') {
                                        try {
-                                               port = (int) UInt32.Parse (portStr);
+                                               port = (int) UInt32.Parse (portStr, CultureInfo.InvariantCulture);
                                                uriString = uriString.Substring (0, pos);
                                        } catch (Exception) {
                                                throw new UriFormatException ("Invalid URI: invalid port number");