package me.teafry.voipmessages; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.TreeSet; /** Phone number helpers, matching the desktop's src/shared/phone.ts. */ final class Phone { private Phone() {} /** Bare 10-digit NANP numbers where possible, else plain digits. */ static String normalize(String raw) { if (raw == null) return ""; String d = raw.replaceAll("\\D", ""); if (d.length() == 11 && d.startsWith("1")) d = d.substring(1); return d; } static String format(String n) { String d = normalize(n); if (d.length() == 10) return "(" + d.substring(0, 3) + ") " + d.substring(3, 6) + "-" + d.substring(6); return n; } static String e164(String n) { String d = normalize(n); return d.length() == 10 ? "+1" + d : "+" + d; } /** Group chats are keyed by their members' numbers, sorted and comma-joined. */ static String groupKey(List numbers) { TreeSet set = new TreeSet<>(); for (String n : numbers) { String d = normalize(n); if (!d.isEmpty()) set.add(d); } return String.join(",", set); } static boolean isGroup(String contact) { return contact.contains(","); } static List members(String contact) { return new ArrayList<>(Arrays.asList(contact.split(","))); } /** voip.ms sends at most 160 characters as one SMS; longer goes as one MMS. */ static final int SMS_TEXT_LIMIT = 160; static int charCount(String s) { return s.codePointCount(0, s.length()); } }