Includes corresponding changes for C++ and JavaScript as well to keep the implementations in sync. (C++ and JS didn't exhibit buggy behavior because the corresponding substring methods don't throw errors for invalid start positions.)
Bugfix for https://github.com/googlei18n/libphonenumber/issues/592
able_to_format_ = true;
is_expecting_country_code_ = false;
possible_formats_.clear();
+ last_match_position_ = 0;
+ formatting_template_.remove();
+ current_formatting_pattern_.clear();
AttemptToChooseFormattingPattern(formatted_number);
}
ableToFormat = true;
isExpectingCountryCallingCode = false;
possibleFormats.clear();
+ lastMatchPosition = 0;
+ formattingTemplate.setLength(0);
+ currentFormattingPattern = "";
return attemptToChooseFormattingPattern();
}
}
private String inputDigitHelper(char nextChar) {
+ // Note that formattingTemplate is not guaranteed to have a value, it could be empty, e.g.
+ // when the next digit is entered after extracting an IDD or NDD.
Matcher digitMatcher = DIGIT_PATTERN.matcher(formattingTemplate);
if (digitMatcher.find(lastMatchPosition)) {
String tempTemplate = digitMatcher.replaceFirst(Character.toString(nextChar));
this.ableToFormat_ = true;
this.isExpectingCountryCallingCode_ = false;
this.possibleFormats_ = [];
+ this.lastMatchPosition_ = 0;
+ this.formattingTemplate_.clear();
+ this.currentFormattingPattern_ = '';
return this.attemptToChooseFormattingPattern_();
};