예제 #1
0
            public static string ReplaceFrom(string sequence, string replacement, MatchingPredicateOptions options)
            {
                var @char = options.GetSingleChar();

                var sb1 = new StringBuilder();
                var sb2 = new StringBuilder();

                for (var i = 0; i < sequence.Length; i++)
                {
                    var index = i;

                    if (sequence[i] == @char)
                    {
                        sb1.Append(replacement);
                        sb2.Append(sequence[i]);
                    }
                    else
                    {
                        sb2.Append(replacement);
                        sb1.Append(sequence[i]);
                    }
                }

                return(options.Not.Ifttt(sb2.ToString, sb1.ToString));
            }
예제 #2
0
            public static bool MatchesAllOf(string sequence, MatchingPredicateOptions options)
            {
                var @char = options.GetSingleChar();

                for (var i = 0; i < sequence.Length; i++)
                {
                    if (sequence[i] != @char)
                    {
                        return(false);
                    }
                }

                return(true);
            }
예제 #3
0
            public static string TrimEndFrom(string sequence, MatchingPredicateOptions options)
            {
                var @char  = options.GetSingleChar();
                var result = sequence.TrimEnd(@char);

                if (options.Not)
                {
                    var times = sequence.Length - result.Length;
                    return(@char.Repeat(times));
                }
                else
                {
                    return(result);
                }
            }
예제 #4
0
            public static string TrimFrom(string sequence, MatchingPredicateOptions options)
            {
                var @char  = options.GetSingleChar();
                var result = sequence.Trim(@char);

                if (options.Not)
                {
                    var(f, l) = CharMatcherUtils.GetHeadAndTailLength(sequence, result);
                    return($"{@char.Repeat(f)}{@char.Repeat(l)}");
                }
                else
                {
                    return(result);
                }
            }
예제 #5
0
            public static string CollapseFrom(string sequence, char replacement, MatchingPredicateOptions options)
            {
                var @char = options.GetSingleChar();
                var sb    = new StringBuilder();

                void UpdateAct(StringBuilder c, char r) => c.Append(r);

                for (var i = 0; i < sequence.Length; i++)
                {
                    var index   = i;
                    var checker = sequence[i] == @char;
                    options.Not.Ifttt(
                        () => checker.Ifttt(() => UpdateAct(sb, sequence[index]), () => UpdateAct(sb, replacement)),
                        () => checker.Ifttt(() => UpdateAct(sb, replacement), () => UpdateAct(sb, sequence[index])));
                }

                return(sb.ToString());
            }
예제 #6
0
            public static string RemoveFrom(string sequence, MatchingPredicateOptions options, bool antiNot = false)
            {
                var @char   = options.GetSingleChar();
                var counter = 0;
                var sb      = new StringBuilder();

                for (var i = 0; i < sequence.Length; i++)
                {
                    if (sequence[i] == @char)
                    {
                        ++counter;
                        continue;
                    }

                    sb.Append(sequence[i]);
                }

                return(antiNot
                    ? options.Not.Ifttt(() => sb.ToString(), () => Strings.Repeat(@char, counter))
                    : options.Not.Ifttt(() => Strings.Repeat(@char, counter), () => sb.ToString()));
            }