Transform mathematical characters

pull/209/head
M66B 2 years ago
parent a782fa3598
commit c4ad9c244a

@ -2396,6 +2396,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ssb.setSpan(new ForegroundColorSpan(textColorLink), start, ssb.length(), 0);
}
} else {
personal = Helper.transformMathematical(personal);
if (full) {
ssb.append(personal).append(" <");
if (!TextUtils.isEmpty(email)) {

@ -2166,6 +2166,44 @@ public class Helper {
return value;
}
static String transformMathematical(String value) {
// https://www.w3.org/TR/xml-entity-names/1D4.html
// https://www.utf8-chartable.de/unicode-utf8-table.pl?start=119808
StringBuilder sb = new StringBuilder();
int k = 0;
while (k < value.length()) {
int cp = value.codePointAt(k);
if (cp >= 0x1D400 && cp <= 0x1D419) // MATHEMATICAL BOLD CAPITAL A-Z
sb.append((char) (cp - 0x1D400 + 65));
else if (cp >= 0x1D41A && cp <= 0x1D433) // MATHEMATICAL BOLD SMALL A-Z
sb.append((char) (cp - 0x1D41A + 97));
else if (cp >= 0x1D434 && cp <= 0x1D44D) // MATHEMATICAL ITALIC CAPITAL A-Z
sb.append((char) (cp - 0x1D434 + 65));
else if (cp >= 0x1D44E && cp <= 0x1D467) // MATHEMATICAL ITALIC SMALL A-Z
sb.append((char) (cp - 0x1D44E + 97));
else if (cp >= 0x1D468 && cp <= 0x1D481) // MATHEMATICAL BOLD ITALIC CAPITAL A-Z
sb.append((char) (cp - 0x1D468 + 65));
else if (cp >= 0x1D482 && cp <= 0x1D49B) // MATHEMATICAL BOLD ITALIC SMALL A-Z
sb.append((char) (cp - 0x1D482 + 97));
else if (cp >= 0x1D49C && cp <= 0x1D4B5) // MATHEMATICAL SCRIPT CAPITAL A-Z
sb.append((char) (cp - 0x1D49C + 65));
else if (cp >= 0x1D4B6 && cp <= 0x1D4CF) // MATHEMATICAL SCRIPT SMALL A-Z
sb.append((char) (cp - 0x1D4B6 + 97));
else if (cp >= 0x1D4D0 && cp <= 0x1D4E9) // MATHEMATICAL BOLD SCRIPT CAPITAL A-Z
sb.append((char) (cp - 0x1D4D0 + 65));
else if (cp >= 0x1D4EA && cp <= 0x1D4FF) // MATHEMATICAL BOLD SCRIPT SMALL A-Z
sb.append((char) (cp - 0x1D4EA + 97));
else
sb.appendCodePoint(cp);
k += Character.charCount(cp);
}
return sb.toString();
}
// Files
static {

@ -2796,7 +2796,8 @@ public class MessageHelper {
}
if (quote)
personal = "\"" + personal + "\"";
}
} else
personal = Helper.transformMathematical(personal);
if (format == AddressFormat.NAME_EMAIL && !TextUtils.isEmpty(email))
formatted.add(personal + " <" + email + ">");

Loading…
Cancel
Save