StripNamespaceColon() 공개 정적인 메소드

Strips trailing colon from a namespace name, e.g. "User:" -> "User"
public static StripNamespaceColon ( string ns ) : string
ns string Namespace string to process
리턴 string
예제 #1
0
        // Covered by RegexTests.GenerateNamespaceRegex()
        /// <summary>
        /// Generates a regex template for all variants of one or more namespace,
        /// e.g. "File|Image"
        /// </summary>
        /// <param name="namespaces">One or more namespaces to process</param>
        public static string GenerateNamespaceRegex(params int[] namespaces)
        {
            StringBuilder sb = new StringBuilder(100 * namespaces.Length);
            foreach (int ns in namespaces)
            {
                if (ns == Namespace.Article) continue;

                if (sb.Length > 0) sb.Append('|');

                string nsName = Variables.Namespaces[ns];
                sb.Append(Tools.StripNamespaceColon(nsName));
                if (Variables.CanonicalNamespaces.ContainsKey(ns) 
                    && Variables.CanonicalNamespaces[ns] != nsName)
                {
                    sb.Append('|');
                    sb.Append(Tools.StripNamespaceColon(Variables.CanonicalNamespaces[ns]));
                }

                if (Variables.NamespaceAliases.ContainsKey(ns))
                    foreach (string s in Variables.NamespaceAliases[ns])
                    {
                        sb.Append('|');
                        sb.Append(Tools.StripNamespaceColon(s));
                    }
            }

            sb.Replace(" ", "[ _]");
            return sb.ToString();
        }
예제 #2
0
        private static void RegenerateRegexes()
        {
            NamespacesCaseInsensitive.Clear();
            bool LangNotEnglish = (LangCode != LangCodeEnum.en);

            foreach (KeyValuePair <int, string> k in Namespaces)
            {
                StringBuilder sb = new StringBuilder("(?i:", 200);
                sb.Append(Tools.StripNamespaceColon(k.Value));
                if (CanonicalNamespaces.ContainsKey(k.Key) && CanonicalNamespaces[k.Key] != k.Value)
                {
                    sb.Append('|');
                    sb.Append(Tools.StripNamespaceColon(CanonicalNamespaces[k.Key]));
                }

                if (NamespaceAliases.ContainsKey(k.Key))
                {
                    foreach (string ns in NamespaceAliases[k.Key])
                    {
                        sb.Append('|');
                        sb.Append(Tools.StripNamespaceColon(ns));
                    }
                }
                // no need to add CanonicalNamespaceAliases here, or...

                sb.Append(@")\s*:");

                NamespacesCaseInsensitive.Add(k.Key, sb.ToString());
            }

            WikiRegexes.MakeLangSpecificRegexes();
        }
예제 #3
0
        // Covered by RegexTests.GenerateNamespaceRegex()
        /// <summary>
        /// Generates a regex template for all variants of one or more namespace,
        /// e.g. "File|Image"
        /// </summary>
        /// <param name="namespaces">One or more namespaces to process</param>
        public static string GenerateNamespaceRegex(params int[] namespaces)
        {
            StringBuilder sb = new StringBuilder(100 * namespaces.Length);

            foreach (int ns in namespaces)
            {
                if (ns == Namespace.Article)
                {
                    continue;
                }

                if (sb.Length > 0)
                {
                    sb.Append('|');
                }

                string nsName = Variables.Namespaces[ns];
                sb.Append(Tools.StripNamespaceColon(nsName));
                string canNS;
                if (Variables.CanonicalNamespaces.TryGetValue(ns, out canNS) &&
                    canNS != nsName)
                {
                    sb.Append('|');
                    sb.Append(Tools.StripNamespaceColon(canNS));
                }

                List <string> nsAlias;
                if (Variables.NamespaceAliases.TryGetValue(ns, out nsAlias))
                {
                    foreach (string s in nsAlias)
                    {
                        sb.Append('|');
                        sb.Append(Tools.StripNamespaceColon(s));
                    }
                }
            }

            sb.Replace(" ", "[ _]");
            return(sb.ToString());
        }