Example #1
0
        public string Parse(string input)
        {
            var finder = new ControlStringFinder('{', ':', '}', '[', ']');

            var controlStrings = finder.FindAllControlStrings(input);

            string result = input;

            foreach (var controlString in controlStrings)
            {

                if (matcher.Matches(controlString))
                {
                    var originalString = input.Substring(controlString.Index, controlString.Length);

                    var specialPrepending = finder.FindPrependingSpecial(originalString.Substring(1, originalString.Length - 2));
                    var specialPostpending = finder.FindPostpendingSpecial(originalString.Substring(1, originalString.Length - 2));

                    var newString = matcher.Match(controlString);

                    newString = string.IsNullOrEmpty(newString) ? newString : specialPrepending + newString + specialPostpending;

                    result = result.Replace(originalString, newString);
                }
            }

            return result;
        }
Example #2
0
        public void FindPostpendingSpecial_IgnoresLeadingCharactersOutsideSpecialStringStarter()
        {
            const char SpecialStringStarter    = '[';
            const char SpecialStringTerminator = ']';

            var input = $"foo{SpecialStringStarter}bar{SpecialStringTerminator}";

            var unit = new ControlStringFinder('{', ':', '}', SpecialStringStarter, SpecialStringTerminator, 'd');

            var expected = "bar";

            // Act
            var result = unit.FindPostpendingSpecial(input);

            result.ShouldBe(expected);
        }
Example #3
0
        public void FindPostpendingSpecial_WhenInputDoesNotEndWithSpecialStringTerminator_ReturnsEmptyString()
        {
            const char SpecialStringStarter    = '[';
            const char SpecialStringTerminator = ']';

            var input = $"{SpecialStringStarter}bar{SpecialStringTerminator}foo";

            var unit = new ControlStringFinder('{', ':', '}', SpecialStringStarter, SpecialStringTerminator, 'd');

            var expected = string.Empty;

            // Act
            var result = unit.FindPostpendingSpecial(input);

            result.ShouldBe(expected);
        }
Example #4
0
 public void FindPostpendingSpecial_WhenInputIsNull_ThrowsArgumentNullException(ControlStringFinder unit)
 {
     Should.Throw <ArgumentNullException>(() => unit.FindPostpendingSpecial(null));
 }
Example #5
0
        public void FindPostpendingSpecial_WhenInputIsEmptyString_ReturnsEmptyString(ControlStringFinder unit)
        {
            var actual = unit.FindPostpendingSpecial(string.Empty);

            actual.ShouldBe(string.Empty);
        }