Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CombineUri()

static string System.Uri.CombineUri ( Uri basePart,
string relativePart,
UriFormat uriFormat )
inlinestaticprivate

Definition at line 3381 of file Uri.cs.

3382 {
3383 char c = relativePart[0];
3384 if (basePart.IsDosPath && (c == '/' || c == '\\') && (relativePart.Length == 1 || (relativePart[1] != '/' && relativePart[1] != '\\')))
3385 {
3386 int num = basePart.OriginalString.IndexOf(':');
3387 if (basePart.IsImplicitFile)
3388 {
3389 return string.Concat(basePart.OriginalString.AsSpan(0, num + 1), relativePart);
3390 }
3391 num = basePart.OriginalString.IndexOf(':', num + 1);
3392 return string.Concat(basePart.OriginalString.AsSpan(0, num + 1), relativePart);
3393 }
3394 if (StaticIsFile(basePart.Syntax) && (c == '\\' || c == '/'))
3395 {
3396 if (relativePart.Length >= 2 && (relativePart[1] == '\\' || relativePart[1] == '/'))
3397 {
3398 if (!basePart.IsImplicitFile)
3399 {
3400 return "file:" + relativePart;
3401 }
3402 return relativePart;
3403 }
3404 if (basePart.IsUnc)
3405 {
3406 ReadOnlySpan<char> readOnlySpan = basePart.GetParts(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.Unescaped);
3407 for (int i = 1; i < readOnlySpan.Length; i++)
3408 {
3409 if (readOnlySpan[i] == '/')
3410 {
3411 readOnlySpan = readOnlySpan.Slice(0, i);
3412 break;
3413 }
3414 }
3415 if (basePart.IsImplicitFile)
3416 {
3417 return string.Concat("\\\\", basePart.GetParts(UriComponents.Host, UriFormat.Unescaped), readOnlySpan, relativePart);
3418 }
3419 return string.Concat("file://", basePart.GetParts(UriComponents.Host, uriFormat), readOnlySpan, relativePart);
3420 }
3421 return "file://" + relativePart;
3422 }
3423 bool flag = basePart.Syntax.InFact(UriSyntaxFlags.ConvertPathSlashes);
3424 string text = null;
3425 if (c == '/' || (c == '\\' && flag))
3426 {
3427 if (relativePart.Length >= 2 && relativePart[1] == '/')
3428 {
3429 return basePart.Scheme + ":" + relativePart;
3430 }
3431 text = ((basePart.HostType != Flags.IPv6HostType) ? basePart.GetParts(UriComponents.SchemeAndServer | UriComponents.UserInfo, uriFormat) : $"{basePart.GetParts(UriComponents.Scheme | UriComponents.UserInfo, uriFormat)}[{basePart.DnsSafeHost}]{basePart.GetParts(UriComponents.Port | UriComponents.KeepDelimiter, uriFormat)}");
3432 if (!flag || c != '\\')
3433 {
3434 return text + relativePart;
3435 }
3436 return text + "/" + relativePart.AsSpan(1);
3437 }
3438 text = basePart.GetParts(UriComponents.Path | UriComponents.KeepDelimiter, basePart.IsImplicitFile ? UriFormat.Unescaped : uriFormat);
3439 int num2 = text.Length;
3440 char[] array = new char[num2 + relativePart.Length];
3441 if (num2 > 0)
3442 {
3443 text.CopyTo(0, array, 0, num2);
3444 while (num2 > 0)
3445 {
3446 if (array[--num2] == '/')
3447 {
3448 num2++;
3449 break;
3450 }
3451 }
3452 }
3454 c = (basePart.Syntax.InFact(UriSyntaxFlags.MayHaveQuery) ? '?' : '\uffff');
3455 char c2 = ((!basePart.IsImplicitFile && basePart.Syntax.InFact(UriSyntaxFlags.MayHaveFragment)) ? '#' : '\uffff');
3456 ReadOnlySpan<char> readOnlySpan2 = string.Empty;
3457 if (c != '\uffff' || c2 != '\uffff')
3458 {
3459 int j;
3460 for (j = 0; j < relativePart.Length && array[num2 + j] != c && array[num2 + j] != c2; j++)
3461 {
3462 }
3463 if (j == 0)
3464 {
3466 }
3467 else if (j < relativePart.Length)
3468 {
3469 readOnlySpan2 = relativePart.AsSpan(j);
3470 }
3471 num2 += j;
3472 }
3473 else
3474 {
3475 num2 += relativePart.Length;
3476 }
3477 if (basePart.HostType == Flags.IPv6HostType)
3478 {
3479 text = ((!basePart.IsImplicitFile) ? (basePart.GetParts(UriComponents.Scheme | UriComponents.UserInfo, uriFormat) + "[" + basePart.DnsSafeHost + "]" + basePart.GetParts(UriComponents.Port | UriComponents.KeepDelimiter, uriFormat)) : ("\\\\[" + basePart.DnsSafeHost + "]"));
3480 }
3481 else if (basePart.IsImplicitFile)
3482 {
3483 if (basePart.IsDosPath)
3484 {
3485 Compress(array, 3, ref num2, basePart.Syntax);
3486 return string.Concat(array.AsSpan(1, num2 - 1), readOnlySpan2);
3487 }
3488 text = "\\\\" + basePart.GetParts(UriComponents.Host, UriFormat.Unescaped);
3489 }
3490 else
3491 {
3492 text = basePart.GetParts(UriComponents.SchemeAndServer | UriComponents.UserInfo, uriFormat);
3493 }
3494 Compress(array, basePart.SecuredPathIndex, ref num2, basePart.Syntax);
3495 return string.Concat(text, array.AsSpan(0, num2), readOnlySpan2);
3496 }
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
string DnsSafeHost
Definition Uri.cs:519
static bool StaticIsFile(UriParser syntax)
Definition Uri.cs:894
static void Compress(char[] dest, int start, ref int destLength, UriParser syntax)
Definition Uri.cs:3300
UriFormat
Definition UriFormat.cs:4

References System.array, System.Uri.Compress(), System.Collections.Generic.Dictionary< TKey, TValue >.CopyTo(), System.Runtime.Serialization.Dictionary, System.Uri.StaticIsFile(), and System.text.

Referenced by System.Uri.GetCombinedString().