Files
m5stack-dashboard/include/text_utils.h
T
2026-08-02 00:25:35 +02:00

36 lines
1.3 KiB
C

#pragma once
#include <Arduino.h>
// The M5Stack default font does not correctly render UTF-8 encoded German
// umlauts (ä, ö, ü, ß), they show up as garbled characters or boxes.
// This helper replaces them with their common ASCII transliteration
// (ö -> oe, ä -> ae, ü -> ue, ß -> ss) before printing to the display.
// This is the simplest, most robust fix without needing a custom font.
inline String sanitizeGermanText(const String &input) {
String out;
out.reserve(input.length());
for (size_t i = 0; i < input.length(); i++) {
unsigned char c1 = input[i];
// UTF-8 two-byte sequences for German umlauts start with 0xC3
if (c1 == 0xC3 && i + 1 < input.length()) {
unsigned char c2 = input[i + 1];
switch (c2) {
case 0xA4: out += "ae"; i++; continue; // ä
case 0xB6: out += "oe"; i++; continue; // ö
case 0xBC: out += "ue"; i++; continue; // ü
case 0x84: out += "Ae"; i++; continue; // Ä
case 0x96: out += "Oe"; i++; continue; // Ö
case 0x9C: out += "Ue"; i++; continue; // Ü
case 0x9F: out += "ss"; i++; continue; // ß
default: break;
}
}
out += (char)c1;
}
return out;
}