Package com.google.i18n.phonenumbers
Class AsYouTypeFormatter
- java.lang.Object
-
- com.google.i18n.phonenumbers.AsYouTypeFormatter
-
public class AsYouTypeFormatter extends Object
A formatter which formats phone numbers as they are entered.An AsYouTypeFormatter can be created by invoking
PhoneNumberUtil.getAsYouTypeFormatter(java.lang.String)
. After that, digits can be added by invokinginputDigit(char)
on the formatter instance, and the partially formatted phone number will be returned each time a digit is added.clear()
can be invoked before formatting a new number.See the unittests for more details on how the formatter is to be used.
- Author:
- Shaopeng Jia
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the internal state of the formatter, so it can be reused.int
getRememberedPosition()
Returns the current position in the partially formatted phone number of the character which was previously passed in as the parameter ofinputDigitAndRememberPosition(char)
.String
inputDigit(char nextChar)
Formats a phone number on-the-fly as each digit is entered.String
inputDigitAndRememberPosition(char nextChar)
Same asinputDigit(char)
, but remembers the position wherenextChar
is inserted, so that it can be retrieved later by usinggetRememberedPosition()
.
-
-
-
Method Detail
-
clear
public void clear()
Clears the internal state of the formatter, so it can be reused.
-
inputDigit
public String inputDigit(char nextChar)
Formats a phone number on-the-fly as each digit is entered.- Parameters:
nextChar
- 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.- Returns:
- the partially formatted phone number.
-
inputDigitAndRememberPosition
public String inputDigitAndRememberPosition(char nextChar)
Same asinputDigit(char)
, but remembers the position wherenextChar
is inserted, so that it can be retrieved later by usinggetRememberedPosition()
. The remembered position will be automatically adjusted if additional formatting characters are later inserted/removed in front ofnextChar
.
-
getRememberedPosition
public int getRememberedPosition()
Returns the current position in the partially formatted phone number of the character which was previously passed in as the parameter ofinputDigitAndRememberPosition(char)
.
-
-