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
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,
// Constructors
-#if MOONLIGHT
- public Uri (string uriString) : this (uriString, UriKind.Absolute)
- {
- }
-#else
public Uri (string uriString) : this (uriString, false)
{
}
-#endif
+
protected Uri (SerializationInfo serializationInfo, StreamingContext streamingContext)
{
string uri = serializationInfo.GetString ("AbsoluteUri");
success = false;
break;
}
+
+ if (success && isAbsoluteUri && (path.Length > 0))
+ path = EscapeString (path);
}
}
query = relativeUri.Substring (pos);
if (!userEscaped)
query = EscapeString (query);
-#if !NET_4_0 && !MOONLIGHT && !MOBILE
+#if !NET_4_0 && !MOBILE
consider_query = query.Length > 0;
#endif
relativeUri = pos == 0 ? String.Empty : relativeUri.Substring (0, pos);
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;
}
}
// return a (pre-allocated) empty array
if (path.Length == 0)
+#if BOOTSTRAP_BASIC
return Empty;
+#else
+ return EmptyArray<string>.Value;
+#endif
// do not return the original array (since items can be changed)
if (segments != null)
return segments.ToArray ();
//
public Uri MakeRelativeUri (Uri uri)
{
-#if NET_4_0 || MOONLIGHT || MOBILE
+#if NET_4_0
if (uri == null)
throw new ArgumentNullException ("uri");
#endif
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;
}
path = EscapeString (path);
}
-#if MOONLIGHT
- static string EscapeString (string str)
-#else
[Obsolete]
protected static string EscapeString (string str)
-#endif
{
return EscapeString (str, Uri.EscapeCommonHexBrackets);
}
path = EscapeString (path);
}
-#if MOONLIGHT
- string Unescape (string path)
-#else
[Obsolete]
protected virtual string Unescape (string path)
-#endif
{
return Unescape (path, false, false);
}
private bool SupportsQuery ()
{
- return ((scheme != Uri.UriSchemeNntp) && (scheme != Uri.UriSchemeFtp) && (scheme != Uri.UriSchemeFile));
+ return UriHelper.SupportsQuery (scheme);
}
//
if (uriString [0] == '/' && Path.DirectorySeparatorChar == '/'){
//Unix Path
ParseAsUnixAbsoluteFilePath (uriString);
-#if MOONLIGHT
- isAbsoluteUri = false;
-#else
if (kind == UriKind.Relative)
isAbsoluteUri = false;
-#endif
return null;
} else if (uriString.Length >= 2 && uriString [0] == '\\' && uriString [1] == '\\') {
//Windows UNC
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;
// 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'
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);
+ }
}
}
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)) {
// 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;
public bool IsBaseOf (Uri uri)
{
-#if NET_4_0 || MOONLIGHT || MOBILE
+#if NET_4_0
if (uri == null)
throw new ArgumentNullException ("uri");
#endif
result = null;
if ((baseUri == null) || !baseUri.IsAbsoluteUri)
return false;
-#if NET_4_0 || MOONLIGHT || MOBILE
+#if NET_4_0
if (relativeUri == null)
return false;
#endif