Beispiel #1
0
        /// <summary>
        /// Deleting not gigit chars with caret management.
        /// </summary>
        /// <param name="state"></param>
        private void NotDigitCharsProcessingWithCaret(ProcessingState state)
        {
            var stringForIteraction = state.Formatting.Text;

            foreach (var @char in stringForIteraction)
            {
                if (CustomSerialilzationChars.Contains(@char))
                {
                    continue;
                }

                // Let's delete only the first entry of that char for now.
                var index = state.Formatting.Text.IndexOf(@char);
                state.Formatting.Text = state.Formatting.Text.Remove(index, 1);

                if (index <= (state.Formatting.CaretPosition - 1))
                {
                    state.Formatting.CaretPosition -= 1;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// The lower implementation of a formatting.
        /// </summary>
        /// <param name="state"></param>
        private void FormatAndManageCaret(ProcessingState state)
        {
            if (state.FormattingType == FormattingAfter.EmptyValueBeforeAndNow)
            {
                return;
            }
            if (state.FormattingType == FormattingAfter.EmptyValueBecome)
            {
                return;
            }

            JumpCaretFromPartialEndToIntegerEnd(state);

            DecimalSeparatorAlternatingReplacing(state);

            if (PartialDisabledOnInput &&
                state.PartialFormatted.IsNotNullOrEmpty())
            {
                state.Formatting.Text = state.IntegerFormatted + DecimalSeparator + ZerosPartialString;
            }
            if (PartialDisabledOnInput &&
                FocusState == FocusState.JustGotten)
            {
                state.Formatting.Text = state.IntegerFormatted;
            }

            DecimalSeparatorDeletedProcessingWithCaret(state);

            // Catch a first digital input and ingnore others.
            if (0 < state.UnformattedValue.Length &&
                state.Formatting.Text.Any(el => CustomSerialilzationChars.Contains(el)) == false)
            {
                state.Formatting.Text          = String.Empty;
                state.Formatting.CaretPosition = 0;

                // !!!
                return;
            }

            DecimalSeparatorMissed(state);
            DecimalSeparatorExcessiveProcessingWithCaret(state);

            GroupSeparatorProcessingWithCaret(state);

            NotDigitCharsProcessingWithCaret(state);

            state.Formatting.Integer = state.IntegerFormatted;
            state.Formatting.Partial = state.PartialFormatted;

            IntegerPartProcessingWithCaret(state);
            PartialPartProcessingWithCaret(state);

            var preliminaryFormattedValue = state.Formatting.Integer;

            if (PartialDisabledCurrent == false)
            {
                preliminaryFormattedValue += DecimalSeparator + state.Formatting.Partial;
            }

            if (RuntimeType == RuntimeType.Double)
            {
                state.Formatting.Text = FormatByPrecisionForDouble(preliminaryFormattedValue);
            }
            else if (RuntimeType == RuntimeType.Decimal)
            {
                state.Formatting.Text = FormatByPrecisionForDecimal(preliminaryFormattedValue);
            }
            else
            {
                WriteLogAction(() => "ERROR. Unsupported typed formatting.");

                state.Formatting.Text = preliminaryFormattedValue;
            }


            if (state.JumpCaretToEndOfInteger)
            {
                state.Formatting.CaretPosition = state.Formatting.Integer.Length;
            }

            CorrectCaretOnEnd(state);
        }