private unsafe static ParsingError GetCombinedString(Uri baseUri, string relativeStr,
bool dontEscape, ref string result)
{
// NB: This is not RFC2396 compliant although it is inline with w3c.org recommendations
// This parser will allow the relativeStr to be an absolute Uri with the different scheme
// In fact this is strict violation of RFC2396
//
for (int i = 0; i < relativeStr.Length; ++i)
{
if (relativeStr[i] == '/' || relativeStr[i] == '\\' || relativeStr[i] == '?' || relativeStr[i] == '#')
{
break;
}
else if (relativeStr[i] == ':')
{
if (i < 2)
{
// Note we don't support one-letter Uri schemes.
// Hence anything like x:sdsd is a relative path and be added to the baseUri Path
break;
}
fixed (char* sptr = relativeStr) // relativeStr.Substring(0, i) represents the scheme
{
UriParser syntax = null;
if (CheckSchemeSyntax(sptr, (ushort)i, ref syntax) == ParsingError.None)
{
if (baseUri.Syntax == syntax)
{
//Remove the scheme for backward Uri parsers compatibility
if (i + 1 < relativeStr.Length)
{
relativeStr = relativeStr.Substring(i + 1);
}
else
{
relativeStr = string.Empty;
}
}
else
{
// This is the place where we switch the scheme.
// Return relative part as the result Uri.
result = relativeStr;
return ParsingError.None;
}
}
}
break;
}
}
if (relativeStr.Length == 0)
{
result = baseUri.OriginalString;
return ParsingError.None;
}
result = CombineUri(baseUri, relativeStr, dontEscape ? UriFormat.UriEscaped : UriFormat.SafeUnescaped);
return ParsingError.None;
}