Browse Source

Small refactoring and documentation updates for AsYouTypeFormatter.java

pull/567/head
Shaopeng Jia 16 years ago
committed by Mihaela Rosca
parent
commit
2891e7ea4f
1 changed files with 15 additions and 17 deletions
  1. +15
    -17
      java/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java

+ 15
- 17
java/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java View File

@ -200,10 +200,7 @@ public class AsYouTypeFormatter {
positionRemembered = originalPosition; positionRemembered = originalPosition;
currentOutput.setLength(0); currentOutput.setLength(0);
} }
if (rememberPosition) {
positionRemembered = accruedInput.length();
originalPosition = positionRemembered;
}
rememberPosition();
return accruedInput.toString(); return accruedInput.toString();
} }
@ -218,18 +215,12 @@ public class AsYouTypeFormatter {
case 3: case 3:
case 4: case 4:
case 5: case 5:
if (rememberPosition) {
positionRemembered = accruedInput.length();
originalPosition = positionRemembered;
}
rememberPosition();
return accruedInput.toString(); return accruedInput.toString();
case 6: case 6:
if (!extractIddAndValidCountryCode()) { if (!extractIddAndValidCountryCode()) {
ableToFormat = false; ableToFormat = false;
if (rememberPosition) {
positionRemembered = accruedInput.length();
originalPosition = positionRemembered;
}
rememberPosition();
return accruedInput.toString(); return accruedInput.toString();
} }
removeNationalPrefixFromNationalNumber(); removeNationalPrefixFromNationalNumber();
@ -243,10 +234,17 @@ public class AsYouTypeFormatter {
} }
} }
private void rememberPosition() {
if (rememberPosition) {
positionRemembered = accruedInput.length();
originalPosition = positionRemembered;
}
}
/** /**
* Same as inputDigit, but remember the position where nextChar is inserted, so that it could be
* retrieved later using getRememberedPosition(). The remembered position will be automatically
* adjusted if additional formatting characters are later inserted/removed in front of it.
* Same as inputDigit, but remembers the position where nextChar is inserted, so that it could be
* retrieved later by using getRememberedPosition(). The remembered position will be automatically
* adjusted if additional formatting characters are later inserted/removed in front of nextChar.
*/ */
public String inputDigitAndRememberPosition(char nextChar) { public String inputDigitAndRememberPosition(char nextChar) {
rememberPosition = true; rememberPosition = true;
@ -257,7 +255,7 @@ public class AsYouTypeFormatter {
/** /**
* Returns the current position in the partially formatted phone number of the character which was * Returns the current position in the partially formatted phone number of the character which was
* previously passed in as the parameter of inputDigitAndRememberPosition.
* previously passed in as the parameter of inputDigitAndRememberPosition().
*/ */
public int getRememberedPosition() { public int getRememberedPosition() {
return positionRemembered; return positionRemembered;
@ -352,7 +350,7 @@ public class AsYouTypeFormatter {
String countryCodeString = Integer.toString(countryCode); String countryCodeString = Integer.toString(countryCode);
if (positionRemembered > prefixBeforeNationalNumber.length() + countryCodeString.length()) { if (positionRemembered > prefixBeforeNationalNumber.length() + countryCodeString.length()) {
// Since a space will be inserted after the country code in this case, we increase the // Since a space will be inserted after the country code in this case, we increase the
// remembered position by 1.
// remembered position by 1.
positionRemembered++; positionRemembered++;
} }
prefixBeforeNationalNumber.append(countryCodeString).append(" "); prefixBeforeNationalNumber.append(countryCodeString).append(" ");


Loading…
Cancel
Save