public static string CanonicalizeTitleAggressively(string title)
{
title = Tools.RemoveHashFromPageTitle(title);
title = Tools.WikiDecode(title).Trim();
title = Tools.TurnFirstToUpper(title);
if (title.StartsWith(":"))
title = title.Remove(0, 1).Trim();
var pos = title.IndexOf(':');
if (pos <= 0)
return title;
string titlePart = title.Substring(0, pos + 1);
foreach (var regex in WikiRegexes.NamespacesCaseInsensitive)
{
var m = regex.Value.Match(titlePart);
if (!m.Success || m.Index != 0)
continue;
title = Variables.Namespaces[regex.Key] + Tools.TurnFirstToUpper(title.Substring(pos + 1).Trim());
break;
}
return title;
}