WikiFunctions.Parse.TypoGroup.Add C# (CSharp) Метод

Add() публичный Метод

Adds one typo regex to the list
public Add ( string typo, string replacement ) : void
typo string
replacement string
Результат void
        public void Add(string typo, string replacement)
        {
            if (!IsSuitableTypo(typo))
            {
                throw new ArgumentException("Typo \"" + typo + "\" is not suitable for this group.");
            }
            Regex r;
            try
            {
                r = new Regex(typo, RegexOptions.Compiled);
            }
            catch (Exception ex)
            {
                RegExTypoFix.TypoError("Error in typo '" + typo + "': " + ex.Message);
                throw new TypoException();
            }

            Typos.Add(new KeyValuePair<Regex, string>(r, replacement));
        }

Usage Example

Пример #1
0
        private void MakeRegexes()
        {
            try
            {
                Typos.Clear();
                TyposCount = 0;
                TypoGroup bounded            = new TypoGroup(20, @"^\\b(.*)\\b$", @"[^\\]\\\d", @"\b", @"\b");
                TypoGroup other              = new TypoGroup(5, null, @"[^\\]\\\d", "", "");
                TypoGroup withBackreferences = new TypoGroup(1, null, null, "", "");

                Typos.Add(bounded);
                Typos.Add(other);
                Typos.Add(withBackreferences);

                Dictionary <string, string> typoStrings = LoadTypos();

                if (TyposLoaded)
                {
                    foreach (KeyValuePair <string, string> k in typoStrings)
                    {
                        if (bounded.SuitableTypo(k.Key))
                        {
                            bounded.Add(k.Key, k.Value);
                        }
                        else
                        if (other.SuitableTypo(k.Key))
                        {
                            other.Add(k.Key, k.Value);
                        }
                        else
                        {
                            withBackreferences.Add(k.Key, k.Value);
                        }

                        TyposCount++;
                    }

                    foreach (TypoGroup grp in Typos)
                    {
                        grp.MakeGroups();
                    }
                }
            }
            catch (TypoException)
            {
                Typos.Clear();
                TyposCount  = 0;
                TyposLoaded = false;
            }
            catch (Exception ex)
            {
                TyposLoaded = false;
                ErrorHandler.Handle(ex);
            }
        }
All Usage Examples Of WikiFunctions.Parse.TypoGroup::Add