WikiFunctions.Parse.Parsers.FixDatesA C# (CSharp) Method

FixDatesA() public method

Fix date and decade formatting errors: commas in American/international dates, full date ranges, month ranges
public FixDatesA ( string articleText ) : string
articleText string
return string
        public string FixDatesA(string articleText)
        {
            if (!Variables.LangCode.Equals("en"))
                return articleText;

            /* performance check: on most articles no date changes, on long articles HideMore is slow, so if no changes to raw text
             * don't need to perform actual check on HideMore text, and this is faster overall
             * Secondly: faster to apply regexes to each date found than to apply regexes to whole article text
             */
            bool changes = false;
            foreach(Match m in MonthsRegexNoSecondBreak.Matches(articleText))
            {
                // take up to 25 characters before match, unless match within first 25 characters of article
                string before = articleText.Substring(m.Index-Math.Min(25, m.Index), Math.Min(25, m.Index)+m.Length);

                string after = FixDatesAInternal(before);

                if (!after.Equals(before))
                {
                    changes = true;
                    break;
                }
            }

            if (!changes)
                return articleText;

            articleText = HideTextImages(articleText);

            articleText = FixDatesAInternal(articleText);

            return AddBackTextImages(articleText);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Removes various unwanted punctuation and comment characters from a derived reference name
        /// </summary>
        /// <param name="derivedName">the input reference name</param>
        /// <returns>the cleaned reference name</returns>
        private static string CleanDerivedReferenceName(string derivedName)
        {
            derivedName = WikiRegexes.PipedWikiLink.Replace(derivedName, "$2"); // piped wikilinks -> text value

            derivedName = CommentOrFloorNumber.Replace(derivedName, "");
            // rm comments from ref name, might be masked
            derivedName = derivedName.Trim(CharsToTrim.ToCharArray());
            derivedName = SequenceOfQuotesInDerivedName.Replace(derivedName, ""); // remove chars
            derivedName = WhitespaceInDerivedName.Replace(derivedName, " "); // spacing fixes
            derivedName = derivedName.Replace(@"&ndash;", "–");

            Parsers p = new Parsers();
            derivedName = p.FixDatesA(derivedName);
            derivedName = p.FixDatesB(derivedName, false, false);

            return DateRetrievedOrAccessed.IsMatch(derivedName) ? "" : derivedName;
        }
Parsers