+ if (url == null)
+ throw new ArgumentNullException ("url");
+
+ // format: "http://host:port/path/to/object"
+ objectURI = null;
+
+ // url needs to be at least "http:" or "https:"
+ if (url.Length < 5 ||
+ (url[0] != 'H' && url[0] != 'h') ||
+ (url[1] != 'T' && url[1] != 't') ||
+ (url[2] != 'T' && url[2] != 't') ||
+ (url[3] != 'P' && url[3] != 'p'))
+ return null;
+
+ int protolen;
+ if (url[4] == 'S' || url[4] == 's') {
+ if (url.Length < 6)
+ return null;
+
+ protolen = 5;
+ } else {
+ protolen = 4;
+ }
+
+ if (url[protolen] != ':')
+ return null;
+
+ // "http:" and "https:" are acceptable inputs
+ if (url.Length == protolen + 1)
+ return url;
+
+ // protocol must be followed by "//"
+ if (url.Length < protolen + 3 || url[protolen + 1] != '/' || url[protolen + 2] != '/')
+ return null;
+
+ // "http://" and "https://" are acceptable inputs
+ if (url.Length == protolen + 3)
+ return url;
+
+ int slash = url.IndexOf ('/', protolen + 3);
+ if (slash == -1)
+ return url;
+
+ objectURI = url.Substring (slash);
+
+ return url.Substring (0, slash);