String ASCII = "", ISO8859 = "";
for (int i = 32; i < 256; i++) { // Show full set of ASCII characters ( > 127 will be ignored)
ASCII += (char)i;
}
Serial.printf (" ASCII: [%s]\nLen: %d\n\n", ASCII.c_str(), ASCII.length());
for (int i = 32; i < 256; i++) { // Show full set of ISO-8859-1 Latin characters (0-255)
ISO8859 += GetUnicodeChar (i);
}
Serial.printf ("ISO8859: [%s]\nLen: %d\n\n", ISO8859.c_str(), ISO8859.length());
String myString = "Questa è una lunga stringa 1234567890 ÒÀÈÙòèàù";
Serial.printf (" ASCII: [%s] Len: %d\n\n", myString.c_str(), myString.length());
myString = GetIsoString (myString);
Serial.printf ("ISO8859: [%s] Len: %d\n\n", myString.c_str(), myString.length());
/////////// ISO-8859-1 //////////
String UNICODE[] = {"", "", "", "", "", "", "", "", "", "", // 128 to 137 (Not used)
"", "", "", "", "", "", "", "", "", "", // 138 to 147 (Not used)
"", "", "", "", "", "", "", "", "", "", // 148 to 157 (Not used)
"", "", " ", "¡", "¢", "£", "¤", "¥", "¦", "§", // 158, 159 (Not used) (160 to 167 used)
"¨", "©", "ª", "«", "¬", "", "®", "¯", "°", "±", // 168 to 177 (used)
"²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", // 178 to 187 (used)
"¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", // 188 to 197 (used)
"Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", // 198 to 207 (used)
"Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", // 208 to 217 (used)
"Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", // 218 to 227 (used)
"ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", // 228 to 237 (used)
"î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", // 238 to 247 (used)
"ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ" // 248 to 255 (used)
};
// This is not a real char, return (one) character but can be one or more bytes,
// so we use String class to collect, we cannot use char to handle a single character
String GetUnicodeChar (uint8_t tByte) {
String out = "";
if (tByte < 128) {
out += (char) tByte; // Append (Mantain the same ASCII code, cast to char)
} else {
out += UNICODE [tByte - 128]; // Append
}
return out;
}
String GetIsoString (String Text) {
String out = "";
uint8_t CurrentByte;
unsigned int len = Text.length();
for (unsigned int i = 0; i < len; i++) {
CurrentByte = (uint8_t) Text[i]; // Or maybe use charAt ?
out += GetUnicodeChar (CurrentByte);
}
return out;
}