Ejemplo n.º 1
0
        public void VerifyEscapeChar()
        {
            var maskedTextProvider = new MaskedTextProvider
                                         (TestSimpleDigitMask, '*', true)
            {
                ResetOnSpace = true
            };

            Assert.True(maskedTextProvider.VerifyEscapeChar(' ', 0));
            Assert.True(maskedTextProvider.VerifyEscapeChar('_', 0));
            Assert.False(maskedTextProvider.VerifyEscapeChar('T', 0));
        }
Ejemplo n.º 2
0
        private static bool CanReplace(MaskedTextProvider provider, string text, int startPosition, int selectionLength, bool rejectInputOnFirstFailure, out int tentativeCaretIndex)
        {
            var endPosition = startPosition + selectionLength - 1;

            tentativeCaretIndex = -1;

            var success = false;

            foreach (var character in text)
            {
                if (!provider.VerifyEscapeChar(character, startPosition))
                {
                    var editPositionFrom = provider.FindEditPositionFrom(startPosition, true);
                    if (editPositionFrom == MaskedTextProvider.InvalidIndex)
                    {
                        break;
                    }
                    startPosition = editPositionFrom;
                }

                var length    = endPosition >= startPosition ? 1 : 0;
                var overwrite = length > 0;

                if (PlaceChar(provider, character, startPosition, length, overwrite, out tentativeCaretIndex))
                {
                    // Only one successfully inserted character is enough to declare the replace operation successful.
                    success       = true;
                    startPosition = tentativeCaretIndex + 1;
                }
                else if (rejectInputOnFirstFailure)
                {
                    return(false);
                }
            }

            if ((selectionLength > 0) && (startPosition <= endPosition))
            {
                // Erase the remaining of the assigned edit character.
                int notUsed;
                MaskedTextResultHint notUsedHint;
                if (!provider.RemoveAt(startPosition, endPosition, out notUsed, out notUsedHint))
                {
                    success = false;
                }
            }

            return(success);
        }