private void delayTextChanged(object sender, TextChangedEventArgs e)
 {
     if (!RegexMatch.NumericMatch((sender as TextBox).Text))
     {
         (sender as TextBox).Text = RegexReplace.MakeNumeric((sender as TextBox).Text);
     }
 }
        // Field santitization. User interface stuff and not part of business logic.
        // Checks as text is typed in and prevents copy paste from violating what we want in the boxes.

        private void searchTextChanged(object sender, TextChangedEventArgs e)
        {
            if (!RegexMatch.CommonNameMatch((sender as TextBox).Text))
            {
                (sender as TextBox).Text = RegexReplace.MakeCommonName((sender as TextBox).Text);
            }
        }
Example #3
0
        private void pageTextChanged(object sender, TextChangedEventArgs e)
        {
            if (!RegexMatch.NumericMatch((sender as TextBox).Text))
            {
                (sender as TextBox).Text = RegexReplace.MakeNumeric((sender as TextBox).Text);
            }

            // This is janky but it works. I could write an event for this, but there are more important things to do.
            if ((sender as TextBox).IsReadOnly)
            {
                (sender as TextBox).Select((sender as TextBox).Text.Length, 0);
            }
        }
Example #4
0
        /// <summary>
        /// Within a specified input string, replaces all groups with the specified number that match the regular expression with a string where each character is replaced with the specified character.
        /// </summary>
        /// <param name="regex">The regular expression to be matched.</param>
        /// <param name="input">The string to search for a match.</param>
        /// <param name="replacementChar">The replacement char.</param>
        /// <param name="groupNumber">A number of the group.</param>
        /// <exception cref="ArgumentNullException"><paramref name="regex"/> or <paramref name="input"/> is <c>null</c>.</exception>
        public static string ReplaceGroupChar(this Regex regex, string input, char replacementChar, int groupNumber)
        {
            if (regex == null)
            {
                throw new ArgumentNullException(nameof(regex));
            }

            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            return(RegexReplace.ReplaceGroups(regex, input, groupNumber, group => new string(replacementChar, group.Length)));
        }
Example #5
0
        public void RegexReplaceRemoveFirstFoo()
        {
            RegexReplace task = new RegexReplace();
            task.BuildEngine = new MockBuild();

            task.Input = TaskUtility.StringArrayToItemArray("foo.my.foo.foo.test.o", "foo.my.faa.foo.test.a", "foo.my.fbb.foo.test.b", "foo.my.fcc.foo.test.c", "foo.my.fdd.foo.test.d");
            task.Expression = new TaskItem("foo\\.");
            task.Count = new TaskItem("1");
            
            Assert.IsTrue(task.Execute(), "Execute Failed");

            foreach (ITaskItem item in task.Output)
            {
                Assert.IsTrue(!item.ItemSpec.StartsWith("foo."), string.Format("Item still starts with foo: {0}", item.ItemSpec));
            }
        }
Example #6
0
        public void RegexReplaceRemoveFirstFoo()
        {
            RegexReplace task = new RegexReplace();

            task.BuildEngine = new MockBuild();

            task.Input      = TaskUtility.StringArrayToItemArray("foo.my.foo.foo.test.o", "foo.my.faa.foo.test.a", "foo.my.fbb.foo.test.b", "foo.my.fcc.foo.test.c", "foo.my.fdd.foo.test.d");
            task.Expression = new TaskItem("foo\\.");
            task.Count      = new TaskItem("1");

            Assert.IsTrue(task.Execute(), "Execute Failed");

            foreach (ITaskItem item in task.Output)
            {
                Assert.IsTrue(!item.ItemSpec.StartsWith("foo."), string.Format("Item still starts with foo: {0}", item.ItemSpec));
            }
        }
Example #7
0
        public void RegexReplaceLastDotForBang()
        {
            RegexReplace task = new RegexReplace();
            task.BuildEngine = new MockBuild();

            task.Input = TaskUtility.StringArrayToItemArray("foo.my.foo.foo.test.o", "foo.my.faa.foo.test.a", "foo.my.fbb.foo.test.b", "foo.my.fcc.foo.test.c", "foo.my.fdd.foo.test.d");
            task.Expression = new TaskItem("\\.");
            task.Replacement = new TaskItem("!");
            task.Count = new TaskItem("1");
            task.Options = TaskUtility.StringArrayToItemArray("RightToLeft");

            Assert.IsTrue(task.Execute(), "Execute Failed");

            foreach (ITaskItem item in task.Output)
            {
                Assert.AreEqual("!", item.ItemSpec.Substring(19, 1), string.Format("Item not replaced properly: {0}", item.ItemSpec));
            }
        }
Example #8
0
        public void RegexReplaceFooForOop()
        {
            RegexReplace task = new RegexReplace();
            task.BuildEngine = new MockBuild();
            string[] expectedResult = new string[] { "foo.my.oop.oop.test.o", "foo.my.faa.oop.test.a", "foo.my.fbb.oop.test.b", "foo.my.fcc.oop.test.c", "foo.my.fdd.oop.test.d" };

            task.Input = TaskUtility.StringArrayToItemArray("foo.my.foo.foo.test.o", "foo.my.faa.foo.test.a", "foo.my.fbb.foo.test.b", "foo.my.fcc.foo.test.c", "foo.my.fdd.foo.test.d");
            task.Expression = new TaskItem("foo\\.");
            task.StartAt = new TaskItem("6");
            task.Replacement = new TaskItem("oop.");

            Assert.IsTrue(task.Execute(), "Execute Failed");

            for (int ndx = 0; ndx < task.Output.Length; ndx++)
            {
                Assert.AreEqual(expectedResult[ndx], task.Output[ndx].ItemSpec, "Results did not match expectations");
            }
        }
Example #9
0
        public void RegexReplaceLastDotForBang()
        {
            RegexReplace task = new RegexReplace();

            task.BuildEngine = new MockBuild();

            task.Input       = TaskUtility.StringArrayToItemArray("foo.my.foo.foo.test.o", "foo.my.faa.foo.test.a", "foo.my.fbb.foo.test.b", "foo.my.fcc.foo.test.c", "foo.my.fdd.foo.test.d");
            task.Expression  = new TaskItem("\\.");
            task.Replacement = new TaskItem("!");
            task.Count       = new TaskItem("1");
            task.Options     = TaskUtility.StringArrayToItemArray("RightToLeft");

            Assert.IsTrue(task.Execute(), "Execute Failed");

            foreach (ITaskItem item in task.Output)
            {
                Assert.AreEqual("!", item.ItemSpec.Substring(19, 1), string.Format("Item not replaced properly: {0}", item.ItemSpec));
            }
        }
Example #10
0
        public void RegexReplaceFooForOop()
        {
            RegexReplace task = new RegexReplace();

            task.BuildEngine = new MockBuild();
            string[] expectedResult = new string[] { "foo.my.oop.oop.test.o", "foo.my.faa.oop.test.a", "foo.my.fbb.oop.test.b", "foo.my.fcc.oop.test.c", "foo.my.fdd.oop.test.d" };

            task.Input       = TaskUtility.StringArrayToItemArray("foo.my.foo.foo.test.o", "foo.my.faa.foo.test.a", "foo.my.fbb.foo.test.b", "foo.my.fcc.foo.test.c", "foo.my.fdd.foo.test.d");
            task.Expression  = new TaskItem("foo\\.");
            task.StartAt     = new TaskItem("6");
            task.Replacement = new TaskItem("oop.");

            Assert.IsTrue(task.Execute(), "Execute Failed");

            for (int ndx = 0; ndx < task.Output.Length; ndx++)
            {
                Assert.AreEqual(expectedResult[ndx], task.Output[ndx].ItemSpec, "Results did not match expectations");
            }
        }
Example #11
0
        // POST api/<controller>
        public string Post([FromBody] RegexReplace req)
        {
            var response = RegexReplace.ProcessRequest(req);

            return(response);
        }