def input_digit(self, next_char, remember_position=False):
        """Formats a phone number on-the-fly as each digit is entered.

        If remember_position is set, remembers the position where next_char is
        inserted, so that it can be retrieved later by using
        get_remembered_position. The remembered position will be automatically
        adjusted if additional formatting characters are later
        inserted/removed in front of next_char.

        Arguments:

        next_char -- The most recently entered digit of a phone
              number. Formatting characters are allowed, but as soon as they
              are encountered this method formats the number as entered and
              not "as you type" anymore. Full width digits and Arabic-indic
              digits are allowed, and will be shown as they are.
        remember_position -- Whether to track the position where next_char is
              inserted.

        Returns the partially formatted phone number.
        """
        self._accrued_input += next_char
        if remember_position:
            self._original_position = len(self._accrued_input)
        # We do formatting on-the-fly only when each character entered is
        # either a digit, or a plus sign (accepted at the start of the number
        # only).
        if not self._is_digit_or_leading_plus_sign(next_char):
            self._able_to_format = False
            self._input_has_formatting = True
        else:
            next_char = self._normalize_and_accrue_digits_and_plus_sign(next_char, remember_position)
        if not self._able_to_format:
            # When we are unable to format because of reasons other than that
            # formatting chars have been entered, it can be due to really long
            # IDDs or NDDs. If that is the case, we might be able to do
            # formatting again after extracting them.
            if self._input_has_formatting:
                self._current_output = self._accrued_input
                return self._current_output
            elif self._attempt_to_extract_idd():
                if self._attempt_to_extract_ccc():
                    self._current_output = self._attempt_to_choose_pattern_with_prefix_extracted()
                    return self._current_output
            elif self._able_to_extract_longer_ndd():
                # Add an additional space to separate long NDD and national
                # significant number for readability. We don't set
                # should_add_space_after_national_prefix to True, since we don't
                # want this to change later when we choose formatting
                # templates.
                self._prefix_before_national_number += _SEPARATOR_BEFORE_NATIONAL_NUMBER
                self._current_output = self._attempt_to_choose_pattern_with_prefix_extracted()
                return self._current_output

            self._current_output = self._accrued_input
            return self._current_output

        # We start to attempt to format only when at least
        # MIN_LEADING_DIGITS_LENGTH digits (the plus sign is counted as a
        # digit as well for this purpose) have been entered.
        len_input = len(self._accrued_input_without_formatting)
        if len_input >= 0 and len_input <= 2:
            self._current_output = self._accrued_input
            return self._current_output
        elif len_input == 3:
            if self._attempt_to_extract_idd():
                self._is_expecting_country_calling_code = True
            else:
                # No IDD or plus sign is found, might be entering in national format.
                self._extracted_national_prefix = self._remove_national_prefix_from_national_number()
                self._current_output = self._attempt_to_choose_formatting_pattern()
                return self._current_output
        if self._is_expecting_country_calling_code:
            if self._attempt_to_extract_ccc():
                self._is_expecting_country_calling_code = False
            self._current_output = self._prefix_before_national_number + self._national_number
            return self._current_output

        if len(self._possible_formats) > 0:  # The formatting patterns are already chosen.
            temp_national_number = self._input_digit_helper(next_char)
            # See if the accrued digits can be formatted properly already. If
            # not, use the results from input_digit_helper, which does
            # formatting based on the formatting pattern chosen.
            formatted_number = self._attempt_to_format_accrued_digits()
            if len(formatted_number) > 0:
                self._current_output = formatted_number
                return self._current_output
            self._narrow_down_possible_formats(self._national_number)
            if self._maybe_create_new_template():
                self._current_output = self._input_accrued_national_number()
                return self._current_output
            if self._able_to_format:
                self._current_output = self._append_national_number(temp_national_number)
                return self._current_output
            else:
                self._current_output = self._accrued_input
                return self._current_output
        else:
            self._current_output = self._attempt_to_choose_formatting_pattern()
            return self._current_output
Formats a phone number on-the-fly as each digit is entered.

        If remember_position is set, remembers the position where next_char is
        inserted, so that it can be retrieved later by using
        get_remembered_position. The remembered position will be automatically
        adjusted if additional formatting characters are later
        inserted/removed in front of next_char.

        Arguments:

        next_char -- The most recently entered digit of a phone
              number. Formatting characters are allowed, but as soon as they
              are encountered this method formats the number as entered and
              not "as you type" anymore. Full width digits and Arabic-indic
              digits are allowed, and will be shown as they are.
        remember_position -- Whether to track the position where next_char is
              inserted.

        Returns the partially formatted phone number.