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

Executes a single find & replace rule against the article text. First applies keywords to the find and replace portions of the rule, then executes the rule. Edit summary is generated from the first match of the rule that changes the article text on replacement. Count of changes is replacements affecting article, not total matches i.e. no-change replacements are not counted in the edit summary
public PerformFindAndReplace ( Replacement rep, string articleText, string articleTitle, bool &changeMade ) : string
rep Replacement F&R rule to execute
articleText string The article text
articleTitle string The article title
changeMade bool Whether the F&R rule caused changes to the article text
Результат string
Пример #1
0
        public void FindAndReplaceNewLines()
        {
            // regex
            WikiFunctions.Parse.Replacement r = new WikiFunctions.Parse.Replacement("foo\n", "bar ", true, true, true, true, RegexOptions.None, "");
            WikiFunctions.Parse.FindandReplace fr = new FindandReplace();
            bool changemade = false;

            Assert.AreEqual("the bar was", fr.PerformFindAndReplace(r, "the foo\nwas", "Test", out changemade));
            Assert.IsTrue(changemade);

            // not regex
            r = new WikiFunctions.Parse.Replacement("foo\n", "bar ", false, true, true, true, RegexOptions.None, "");
            Assert.AreEqual("the bar was", fr.PerformFindAndReplace(r, "the foo\nwas", "Test", out changemade));
            Assert.IsTrue(changemade);
        }
Пример #2
0
        public void FindAndReplaceRemove()
        {
            WikiFunctions.Parse.Replacement r = new WikiFunctions.Parse.Replacement("foo", "", true, true, true, true, RegexOptions.None, "");

            WikiFunctions.Parse.FindandReplace fr = new FindandReplace();

            bool changemade = false;

            Assert.AreEqual(fr.PerformFindAndReplace(r, "the was", "Test", out changemade), "the was");
            Assert.IsFalse(changemade);
            Assert.AreEqual(null, fr.ReplacedSummary, "No match: no edit summary");
            Assert.AreEqual(null, fr.RemovedSummary, "No match: no edit summary");

            Assert.AreEqual(fr.PerformFindAndReplace(r, "the foo was", "Test", out changemade), "the  was");
            Assert.IsTrue(changemade);
            Assert.AreEqual("foo", fr.RemovedSummary, "One match: removed a");

            fr = new FindandReplace();
            changemade = false;

            Assert.AreEqual(fr.PerformFindAndReplace(r, "the foo was or foo was", "Test", out changemade), "the  was or  was");
            Assert.AreEqual("foo (2)", fr.RemovedSummary, "Match count shown");

            r = new WikiFunctions.Parse.Replacement("foot?", "", true, true, true, true, RegexOptions.None, "");
            fr = new FindandReplace();
            changemade = false;

            Assert.AreEqual(fr.PerformFindAndReplace(r, "the foot was or foo was", "Test", out changemade), "the  was or  was");
            Assert.IsTrue(changemade);
            Assert.AreEqual("foot (2)", fr.RemovedSummary, "Different matches, match text of first used");
        }
Пример #3
0
        public void FindAndReplace()
        {
            WikiFunctions.Parse.Replacement r = new WikiFunctions.Parse.Replacement("foo", "bar", true, true, true, true, RegexOptions.None, "");

            WikiFunctions.Parse.FindandReplace fr = new FindandReplace();

            bool changemade = false;

            Assert.AreEqual(fr.PerformFindAndReplace(r, "the was", "Test", out changemade), "the was");
            Assert.IsFalse(changemade);
            Assert.AreEqual(null, fr.ReplacedSummary, "No match: no edit summary");

            Assert.AreEqual(fr.PerformFindAndReplace(r, "the foo was", "Test", out changemade), "the bar was");
            Assert.IsTrue(changemade);
            Assert.AreEqual("foo" + WikiFunctions.Parse.FindandReplace.Arrow + "bar", fr.ReplacedSummary, "One match: a to b");

            fr = new FindandReplace();
            changemade = false;

            Assert.AreEqual(fr.PerformFindAndReplace(r, "the foo was or foo was", "Test", out changemade), "the bar was or bar was");
            Assert.AreEqual("foo" + WikiFunctions.Parse.FindandReplace.Arrow + "bar (2)", fr.ReplacedSummary, "Match count shown");

            fr = new FindandReplace();
            changemade = false;

            Assert.AreEqual(fr.PerformFindAndReplace(r, "the foo was or foo was foo", "Test", out changemade), "the bar was or bar was bar");
            Assert.AreEqual("foo" + WikiFunctions.Parse.FindandReplace.Arrow + "bar (3)", fr.ReplacedSummary, "Match count shown, 3");

            r = new WikiFunctions.Parse.Replacement("foot?", "bar", true, true, true, true, RegexOptions.None, "");
            fr = new FindandReplace();
            changemade = false;

            Assert.AreEqual(fr.PerformFindAndReplace(r, "the foot was or foo was", "Test", out changemade), "the bar was or bar was");
            Assert.IsTrue(changemade);
            Assert.AreEqual("foot" + WikiFunctions.Parse.FindandReplace.Arrow + "bar (2)", fr.ReplacedSummary, "Different matches, match text of first used");

            r = new WikiFunctions.Parse.Replacement("fooo?", "foo", true, true, true, true, RegexOptions.None, "");
            fr = new FindandReplace();
            changemade = false;
            Assert.AreEqual(fr.PerformFindAndReplace(r, "the foo was a fooo it", "Test", out changemade), "the foo was a foo it");
            Assert.IsTrue(changemade);
            Assert.AreEqual("fooo" + WikiFunctions.Parse.FindandReplace.Arrow + "foo", fr.ReplacedSummary, "No-change match ignored");

            fr = new FindandReplace();
            changemade = false;
            Assert.AreEqual(fr.PerformFindAndReplace(r, "the foo was", "Test", out changemade), "the foo was");
            Assert.IsFalse(changemade, "only match is no-change on replace, so no change made");
            Assert.AreEqual(null, fr.ReplacedSummary, "Only match is No-change match, no edit summary");
        }