System.ComponentModel.MaskedTextProvider.TestString C# (CSharp) Method

TestString() private method

Test the characters in the specified string agaist the test string, starting from the specified position. On exit the testPosition contains last position where the primary operation was actually performed if successful, otherwise the first position that made the test fail. This position is relative to the test string. The successCount out param contains the number of characters that would be actually set (not escaped). The MaskedTextResultHint out param gives more information about the operation result. Returns true on success, false otherwise.
private TestString ( string input, int position, int &testPosition, MaskedTextResultHint &resultHint ) : bool
input string
position int
testPosition int
resultHint MaskedTextResultHint
return bool
        private bool TestString(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
        {
            Debug.Assert(input != null, "null input.");
            Debug.Assert(position >= 0, "Position out of range.");

            resultHint = MaskedTextResultHint.Unknown;
            testPosition = position;

            if (input.Length == 0)
            {
                return true;
            }

            // If any char is actually accepted, then the hint is success, otherwise whatever the last character result is.
            // Need a temp variable for 
            MaskedTextResultHint tempHint = resultHint;

            foreach (char ch in input)
            {
                if (testPosition >= _testString.Length)
                {
                    resultHint = MaskedTextResultHint.UnavailableEditPosition;
                    return false;
                }

                // If character is not to be escaped, we need to find an edit position to test it in.
                if (!TestEscapeChar(ch, testPosition))
                {
                    testPosition = FindEditPositionFrom(testPosition, forward);

                    if (testPosition == invalidIndex)
                    {
                        testPosition = _testString.Length;
                        resultHint = MaskedTextResultHint.UnavailableEditPosition;
                        return false;
                    }
                }

                // Test/Set char will scape prompt, space and literals if needed.
                if (!TestChar(ch, testPosition, out tempHint))
                {
                    resultHint = tempHint;
                    return false;
                }

                // Result precedence: Success, SideEffect, NoEffect, CharacterEscaped.
                if (tempHint > resultHint)
                {
                    resultHint = tempHint;
                }

                testPosition++;
            }

            testPosition--;

            return true;
        }