Utils: Fix SplitName() for double names
All checks were successful
Test / Run tests (push) Successful in 1m46s

This commit is contained in:
2024-09-17 19:18:43 +02:00
parent a18b58f438
commit 871bc299bd

View File

@ -348,7 +348,7 @@ namespace Elwig.Helpers {
}
public static (string, string?) SplitName(string fullName, string? familyName) {
if (familyName == null || familyName == "") return (fullName, null);
if (string.IsNullOrWhiteSpace(familyName)) return (fullName, null);
var p0 = fullName.IndexOf(familyName, StringComparison.CurrentCultureIgnoreCase);
if (p0 == -1) return (fullName, null);
var p1 = fullName.IndexOf(" und ");
@ -362,8 +362,10 @@ namespace Elwig.Helpers {
var p3 = fullName.LastIndexOf(' ', p2 - 1);
return (fullName[0..p3], fullName[(p3 + 1)..^0]);
}
} else {
} else if (p0 + familyName.Length >= fullName.Length || fullName[p0 + familyName.Length] == ' ') {
return (familyName, fullName.Replace(familyName, "").Replace(" ", " ").Trim());
} else {
return (fullName, null);
}
}