// Covered by: NamespaceTests.Determine
/// <summary>
/// Deduces the namespace number from the input article title.
/// </summary>
public static int Determine(string articleTitle)
{
articleTitle = ColonSpace.Replace(articleTitle.Replace("%3A", ":"), ":");
/* if there is a spacing modifying character at the start of the articletitle it will mean the article full name will never contain "Namespace:"
* as the colon and modifier will combine to some other Unicode character, so remove any such modifier characters to allow correct derivation */
articleTitle = SpacingModifierLetters.Replace(articleTitle, @"'");
if (!articleTitle.Contains(":"))
{
return(0);
}
articleTitle = Tools.TurnFirstToUpper(Tools.WikiDecode(articleTitle));
foreach (KeyValuePair <int, string> k in Variables.Namespaces)
{
if (articleTitle.StartsWith(k.Value))
{
return(articleTitle.Length >= k.Value.Length ? k.Key : 0);
}
}
foreach (KeyValuePair <int, List <string> > k in Variables.NamespaceAliases)
{
foreach (string s in k.Value)
{
if (articleTitle.StartsWith(s))
{
return(articleTitle.Length >= s.Length ? k.Key : 0);
}
}
}
foreach (KeyValuePair <int, string> k in Variables.CanonicalNamespaces)
{
if (articleTitle.StartsWith(k.Value))
{
return(articleTitle.Length >= k.Value.Length ? k.Key : 0);
}
}
return(0);
}