X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem%2FSystem%2FUri.cs;h=5749967985ba77c32e188d7205f53bc06ff7eecf;hb=c4508573a962d7e9ea34daf2b4fdb48b4e4c3e44;hp=9e8c8cd6eb58a8c956fd382df66bdac04ef181bb;hpb=11ab0e0864af8f10c07c38d90c518f719f282f2e;p=mono.git diff --git a/mcs/class/System/System/Uri.cs b/mcs/class/System/System/Uri.cs index 9e8c8cd6eb5..5749967985b 100644 --- a/mcs/class/System/System/Uri.cs +++ b/mcs/class/System/System/Uri.cs @@ -90,10 +90,25 @@ namespace System { private string cachedToString; private string cachedLocalPath; private int cachedHashCode; + +#if NET_4_5 + private static volatile bool s_IriParsing = true; +#else + private static volatile bool s_IriParsing = false; +#endif + public static bool IriParsing { + get { return s_IriParsing; } + set { s_IriParsing = value; } + } + +#if BOOTSTRAP_BASIC private static readonly string hexUpperChars = "0123456789ABCDEF"; private static readonly string [] Empty = new string [0]; private static bool isWin32 = (Path.DirectorySeparatorChar == '\\'); +#else + static readonly char[] hexUpperChars = new [] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; +#endif // Fields @@ -108,7 +123,11 @@ namespace System { public static readonly string UriSchemeNntp = "nntp"; public static readonly string UriSchemeNetPipe = "net.pipe"; public static readonly string UriSchemeNetTcp = "net.tcp"; - + + internal static readonly string UriSchemeTelnet = "telnet"; + internal static readonly string UriSchemeLdap = "ldap"; + internal static readonly string UriSchemeUuid = "uuid"; + private static readonly string [] knownUriSchemes = { UriSchemeFile, @@ -459,13 +478,10 @@ namespace System { public string AbsoluteUri { get { EnsureAbsoluteUri (); - if (cachedAbsoluteUri == null) { - cachedAbsoluteUri = GetLeftPart (UriPartial.Path); - if (query.Length > 0) - cachedAbsoluteUri += query; - if (fragment.Length > 0) - cachedAbsoluteUri += fragment; - } + + if (cachedAbsoluteUri == null) + cachedAbsoluteUri = GetComponents (UriComponents.AbsoluteUri, UriFormat.UriEscaped); + return cachedAbsoluteUri; } } @@ -646,7 +662,11 @@ namespace System { // return a (pre-allocated) empty array if (path.Length == 0) +#if BOOTSTRAP_BASIC return Empty; +#else + return EmptyArray.Value; +#endif // do not return the original array (since items can be changed) if (segments != null) return segments.ToArray (); @@ -1087,13 +1107,10 @@ namespace System { if (cachedToString != null) return cachedToString; - if (isAbsoluteUri) { - cachedToString = Unescape (GetLeftPart (UriPartial.Path), true); - AppendQueryAndFragment (ref cachedToString); - } else { - // Everything is contained in path in this case. - cachedToString = path; - } + if (isAbsoluteUri) + cachedToString = parser.GetComponentsHelper (this, UriComponents.AbsoluteUri, UriHelper.ToStringUnescape); + else + cachedToString = UriHelper.FormatRelative (source, scheme, UriHelper.ToStringUnescape); return cachedToString; } @@ -1346,7 +1363,7 @@ namespace System { private bool SupportsQuery () { - return ((scheme != Uri.UriSchemeNntp) && (scheme != Uri.UriSchemeFtp) && (scheme != Uri.UriSchemeFile)); + return UriHelper.SupportsQuery (scheme); } // @@ -1435,6 +1452,10 @@ namespace System { scheme = TryGetKnownUriSchemeInstance (scheme); + var formatFlags = UriHelper.FormatFlags.None; + if (UriHelper.HasCharactersToNormalize (uriString)) + formatFlags |= UriHelper.FormatFlags.HasUriCharactersToNormalize; + // from here we're practically working on uriString.Substring(startpos,endpos-startpos) int startpos = pos + 1; int endpos = uriString.Length; @@ -1442,12 +1463,12 @@ namespace System { // 8 fragment pos = uriString.IndexOf ('#', startpos); if (!IsUnc && pos != -1) { - if (userEscaped) - fragment = uriString.Substring (pos); - else - fragment = "#" + EscapeString (uriString.Substring (pos+1)); - + fragment = uriString.Substring (pos); endpos = pos; + if (!userEscaped) { + fragment = "#" + UriHelper.FormatAbsolute(fragment.Substring (1), scheme, + UriComponents.Fragment, UriFormat.UriEscaped, formatFlags); + } } // special case: there is no query part for 'news' @@ -1464,8 +1485,10 @@ namespace System { if (pos != -1) { query = uriString.Substring (pos, endpos-pos); endpos = pos; - if (!userEscaped) - query = EscapeString (query); + if (!userEscaped){ + query = "?" + UriHelper.FormatAbsolute(query.Substring (1), scheme, + UriComponents.Query, UriFormat.UriEscaped, formatFlags); + } } } @@ -1598,7 +1621,11 @@ namespace System { host = String.Empty; } else if (scheme == UriSchemeFile) { // under Windows all file:// URI are considered UNC, which is not the case other MacOS (e.g. Silverlight) +#if BOOTSTRAP_BASIC isUnc = isWin32; +#else + isUnc = Environment.IsRunningOnWindows; +#endif } else if (host.Length == 0 && (scheme == UriSchemeHttp || scheme == UriSchemeGopher || scheme == UriSchemeNntp || scheme == UriSchemeHttps || scheme == UriSchemeFtp)) { @@ -1768,7 +1795,7 @@ namespace System { // A variant of HexUnescape() which can decode multi-byte escaped // sequences such as (e.g.) %E3%81%8B into a single character - private static char HexUnescapeMultiByte (string pattern, ref int index, out char surrogate) + internal static char HexUnescapeMultiByte (string pattern, ref int index, out char surrogate) { surrogate = char.MinValue;