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

Commit 4eb45cc9 authored by inshik's avatar inshik Committed by Jaikumar Ganesh
Browse files

Add utility functions for pause and tonewait pause.

Add a function that converts a string with RFC3601 defintion
of pause and wait into android representation.

Change-Id: Id8a17c3a166422d62247acb227506549990ace12
parent 89d55ad7
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -122,6 +122,17 @@ public class PhoneNumberUtils
        return c == PAUSE || c == WAIT;
    }

    private static boolean
    isPause (char c){
        return c == 'p'||c == 'P';
    }

    private static boolean
    isToneWait (char c){
        return c == 'w'||c == 'W';
    }


    /** Returns true if ch is not dialable or alpha char */
    private static boolean isSeparator(char ch) {
        return !isDialable(ch) && !(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'));
@@ -278,6 +289,32 @@ public class PhoneNumberUtils
        return ret.toString();
    }

    /**
     * Converts pause and tonewait pause characters
     * to Android representation.
     * RFC 3601 says pause is 'p' and tonewait is 'w'.
     * @hide
     */
    public static String convertPreDial(String phoneNumber) {
        if (phoneNumber == null) {
            return null;
        }
        int len = phoneNumber.length();
        StringBuilder ret = new StringBuilder(len);

        for (int i = 0; i < len; i++) {
            char c = phoneNumber.charAt(i);

            if (isPause(c)) {
                c = PAUSE;
            } else if (isToneWait(c)) {
                c = WAIT;
            }
            ret.append(c);
        }
        return ret.toString();
    }

    /** or -1 if both are negative */
    static private int
    minPositive (int a, int b) {