mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-04 16:16:33 +02:00
Auto recognize ISO-2022-JP
This commit is contained in:
@@ -961,52 +961,6 @@ public class Helper {
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean isUTF8(String text) {
|
||||
// Get extended ASCII characters
|
||||
byte[] octets = text.getBytes(StandardCharsets.ISO_8859_1);
|
||||
|
||||
int bytes;
|
||||
for (int i = 0; i < octets.length; i++) {
|
||||
if ((octets[i] & 0b10000000) == 0b00000000)
|
||||
bytes = 1;
|
||||
else if ((octets[i] & 0b11100000) == 0b11000000)
|
||||
bytes = 2;
|
||||
else if ((octets[i] & 0b11110000) == 0b11100000)
|
||||
bytes = 3;
|
||||
else if ((octets[i] & 0b11111000) == 0b11110000)
|
||||
bytes = 4;
|
||||
else if ((octets[i] & 0b11111100) == 0b11111000)
|
||||
bytes = 5;
|
||||
else if ((octets[i] & 0b11111110) == 0b11111100)
|
||||
bytes = 6;
|
||||
else
|
||||
return false;
|
||||
|
||||
if (i + bytes > octets.length)
|
||||
return false;
|
||||
|
||||
while (--bytes > 0)
|
||||
if ((octets[++i] & 0b11000000) != 0b10000000)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean isISO8859(String text) {
|
||||
// https://en.wikipedia.org/wiki/ISO/IEC_8859-1
|
||||
int c;
|
||||
byte[] octets = text.getBytes(StandardCharsets.ISO_8859_1);
|
||||
for (byte b : octets) {
|
||||
c = b & 0xFF;
|
||||
if (c < 32)
|
||||
return false;
|
||||
if (c >= 127 && c < 160)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean isSingleScript(String s) {
|
||||
// https://en.wikipedia.org/wiki/IDN_homograph_attack
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
|
||||
|
||||
Reference in New Issue
Block a user