Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5261874 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 2503

* changes:
  Stop the NANP number formatter from putting dashes in shortcodes.
parents 6742fa73 5214376d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1003,6 +1003,7 @@ public class PhoneNumberUtils
     * as:
     *
     * <p><code>
     * xxxxx
     * xxx-xxxx
     * xxx-xxx-xxxx
     * 1-xxx-xxx-xxxx
@@ -1016,7 +1017,11 @@ public class PhoneNumberUtils
        if (length > "+1-nnn-nnn-nnnn".length()) {
            // The string is too long to be formatted
            return;
        } else if (length <= 5) {
            // The string is either a shortcode or too short to be formatted
            return;
        }

        CharSequence saved = text.subSequence(0, length);

        // Strip the dashes first, as we're going to add them back
+5 −0
Original line number Diff line number Diff line
@@ -302,6 +302,11 @@ public class PhoneNumberUtilsTest extends TestCase {
        number.append("800-55512");
        PhoneNumberUtils.formatNanpNumber(number);
        assertEquals("800-555-12", number.toString());

        number.clear();
        number.append("46645");
        PhoneNumberUtils.formatNanpNumber(number);
        assertEquals("46645", number.toString());
    }

    @SmallTest