Exemplo n.º 1
0
        /// <summary>
        /// compute the ovelaps array on finding matching prefixes with suffixes
        /// </summary>
        /// <returns></returns>
        public int[] Compute()
        {
            var patternLen = Pattern.Length;
            var res        = new int[patternLen];

            res[0] = 0;
            var iterator = 0;

            for (var index = 1; index < patternLen; index++)
            {
                var currentChar = Pattern[index];
                while (iterator > 0 && !CharEquality.IsCharEqual(Pattern[iterator], currentChar, IsCaseSensitive))
                {
                    iterator = res[iterator];
                }

                if (CharEquality.IsCharEqual(Pattern[iterator], currentChar, IsCaseSensitive))
                {
                    iterator += 1;
                }
                res[index] = iterator;
            }

            return(res);
        }
Exemplo n.º 2
0
        /// <summary>
        /// calculate all matches of chars in the Text and SubText strings
        /// </summary>
        /// <param name="indexText">location in text for current algo iteration</param>
        /// <param name="indexPattern">location in pattern for current algo iteration</param>
        /// <param name="patternLength">string length of pattern string</param>
        /// <returns></returns>
        private bool MatchStrings(ref int indexText, ref int indexPattern, int patternLength)
        {
            while (
                indexPattern <= patternLength &&
                CharEquality.IsCharEqual(this.Text[indexText], this.SubText[indexPattern], IsCaseSensitive))
            {
                indexPattern += 1;
                indexText    += 1;
            }

            return(indexPattern > patternLength);
        }
Exemplo n.º 3
0
        public void CaseInsensitiveDefault()
        {
            var equal = CharEquality.IsCharEqual('A', 'a');

            Assert.IsTrue(equal);
        }
Exemplo n.º 4
0
        public void CaseInsensitiveMethod()
        {
            var equal = CharEquality.IsCharEqual('A', 'a', false);

            Assert.IsTrue(equal);
        }
Exemplo n.º 5
0
        public void CaseSensitiveMethod()
        {
            var equal = CharEquality.IsCharEqual('A', 'a', true);

            Assert.IsFalse(equal);
        }