public static WikiDecode ( string title ) : string | ||
title | string | Page title to decode |
return | string |
// 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); }
// Covered by NamespaceTests.NormalizeNamespace() /// <summary> /// Normalizes a namespace string, but does not changes it to default namespace name /// </summary> public static string Normalize(string ns, int nsId) { ns = Tools.WikiDecode(NormalizeColon.Replace(ns, ":")); if (Variables.Namespaces[nsId].Equals(ns, StringComparison.InvariantCultureIgnoreCase)) { return(Variables.Namespaces[nsId]); } foreach (string s in Variables.NamespaceAliases[nsId]) { if (s.Equals(ns, StringComparison.InvariantCultureIgnoreCase)) { return(s); } } // fail return(ns); }
// Covered by: NamespaceTests.Determine /// <summary> /// Deduces the namespace number from the input article title. /// </summary> public static int Determine(string articleTitle) { articleTitle = Tools.TurnFirstToUpper(Regex.Replace(articleTitle, @"\s*:\s*", ":")); articleTitle = Tools.WikiDecode(articleTitle); if (!articleTitle.Contains(":")) { return(0); } 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); }