Update UCS-2 converter
This commit is contained in:
+20
-29
@@ -1402,7 +1402,7 @@ void TEF6686::readRDS(byte showrdserrors) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (offset == 0 || foundendmarker) {
|
if (offset == 0 || foundendmarker) {
|
||||||
if (eRTcoding) rds.enhancedRTtext = eRT_buffer; else rds.enhancedRTtext = utf8ToUcs2String(eRT_buffer); // Convert to UTF-8 or UCS-2
|
if (eRTcoding) rds.enhancedRTtext = eRT_buffer; else rds.enhancedRTtext = ucs2ToUtf8(eRT_buffer); // Convert to UTF-8 or UCS-2
|
||||||
rds.enhancedRTtext = trimTrailingSpaces(rds.enhancedRTtext);
|
rds.enhancedRTtext = trimTrailingSpaces(rds.enhancedRTtext);
|
||||||
if (rds.enhancedRTtext.length() > 0) rds.hasEnhancedRT = true;
|
if (rds.enhancedRTtext.length() > 0) rds.hasEnhancedRT = true;
|
||||||
}
|
}
|
||||||
@@ -1980,36 +1980,27 @@ String TEF6686::trimTrailingSpaces(String str) {
|
|||||||
return str.substring(0, end + 1);
|
return str.substring(0, end + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String TEF6686::utf8ToUcs2String(const char* utf8) {
|
String TEF6686::ucs2ToUtf8(const char* ucs2Input) {
|
||||||
String ucs2;
|
String utf8Output;
|
||||||
while (*utf8) {
|
|
||||||
uint32_t codepoint = 0;
|
|
||||||
int extraBytes = 0;
|
|
||||||
|
|
||||||
if ((*utf8 & 0x80) == 0) {
|
size_t length = 0;
|
||||||
codepoint = *utf8++;
|
while (ucs2Input[length] != '\0' || ucs2Input[length + 1] != '\0') {
|
||||||
} else if ((*utf8 & 0xE0) == 0xC0) {
|
length += 2;
|
||||||
codepoint = *utf8++ & 0x1F;
|
}
|
||||||
extraBytes = 1;
|
|
||||||
} else if ((*utf8 & 0xF0) == 0xE0) {
|
for (size_t i = 0; i < length; i += 2) {
|
||||||
codepoint = *utf8++ & 0x0F;
|
uint16_t ucs2Char = ((uint8_t)ucs2Input[i] << 8) | (uint8_t)ucs2Input[i + 1];
|
||||||
extraBytes = 2;
|
|
||||||
} else if ((*utf8 & 0xF8) == 0xF0) {
|
if (ucs2Char <= 0x7F) {
|
||||||
codepoint = *utf8++ & 0x07;
|
utf8Output += (char)ucs2Char;
|
||||||
extraBytes = 3;
|
} else if (ucs2Char <= 0x7FF) {
|
||||||
|
utf8Output += (char)(0xC0 | (ucs2Char >> 6));
|
||||||
|
utf8Output += (char)(0x80 | (ucs2Char & 0x3F));
|
||||||
} else {
|
} else {
|
||||||
continue;
|
utf8Output += (char)(0xE0 | (ucs2Char >> 12));
|
||||||
}
|
utf8Output += (char)(0x80 | ((ucs2Char >> 6) & 0x3F));
|
||||||
|
utf8Output += (char)(0x80 | (ucs2Char & 0x3F));
|
||||||
for (int i = 0; i < extraBytes; i++) {
|
|
||||||
if ((*utf8 & 0xC0) != 0x80) break;
|
|
||||||
codepoint = (codepoint << 6) | (*utf8++ & 0x3F);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (codepoint <= 0xFFFF) {
|
|
||||||
ucs2 += (char)(codepoint >> 8); // High byte
|
|
||||||
ucs2 += (char)(codepoint & 0xFF); // Low byte
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ucs2;
|
return utf8Output;
|
||||||
}
|
}
|
||||||
+6
-6
@@ -721,15 +721,15 @@ class TEF6686 {
|
|||||||
String convertToUTF8(const wchar_t* input);
|
String convertToUTF8(const wchar_t* input);
|
||||||
String extractUTF8Substring(const String& utf8String, size_t start, size_t length, bool under);
|
String extractUTF8Substring(const String& utf8String, size_t start, size_t length, bool under);
|
||||||
String trimTrailingSpaces(String str);
|
String trimTrailingSpaces(String str);
|
||||||
String eRTconverter(const wchar_t* input);
|
String eRTconverter(const wchar_t* input);
|
||||||
String utf8ToUcs2String(const char* utf8);
|
String ucs2ToUtf8(const char* ucs2Input);
|
||||||
char ps_buffer[9];
|
char ps_buffer[9];
|
||||||
char ps_buffer2[9];
|
char ps_buffer2[9];
|
||||||
char ptyn_buffer[9];
|
char ptyn_buffer[9];
|
||||||
char eon_buffer[20][9];
|
char eon_buffer[20][9];
|
||||||
bool ps_process;
|
bool ps_process;
|
||||||
bool pslong_process;
|
bool pslong_process;
|
||||||
char eRT_buffer[129];
|
char eRT_buffer[129];
|
||||||
bool rt_process;
|
bool rt_process;
|
||||||
char rt_buffer[65];
|
char rt_buffer[65];
|
||||||
char rt_buffer2[65];
|
char rt_buffer2[65];
|
||||||
@@ -740,7 +740,7 @@ class TEF6686 {
|
|||||||
bool ABold;
|
bool ABold;
|
||||||
bool afreset;
|
bool afreset;
|
||||||
bool mpxmode;
|
bool mpxmode;
|
||||||
bool _hasEnhancedRT;
|
bool _hasEnhancedRT;
|
||||||
char stationTextBuffer[65];
|
char stationTextBuffer[65];
|
||||||
uint16_t piold;
|
uint16_t piold;
|
||||||
bool rtABold;
|
bool rtABold;
|
||||||
@@ -765,7 +765,7 @@ class TEF6686 {
|
|||||||
bool rdsDerrorThreshold;
|
bool rdsDerrorThreshold;
|
||||||
bool packet0, packet1, packet2, packet3, packet0long, packet1long, packet2long, packet3long;
|
bool packet0, packet1, packet2, packet3, packet0long, packet1long, packet2long, packet3long;
|
||||||
bool afmethodBprobe;
|
bool afmethodBprobe;
|
||||||
bool eRTcoding;
|
bool eRTcoding;
|
||||||
uint16_t rdsCold;
|
uint16_t rdsCold;
|
||||||
uint8_t af_counterb;
|
uint8_t af_counterb;
|
||||||
uint8_t af_number;
|
uint8_t af_number;
|
||||||
@@ -774,7 +774,7 @@ class TEF6686 {
|
|||||||
uint16_t correctPIold;
|
uint16_t correctPIold;
|
||||||
uint8_t rtplusblock;
|
uint8_t rtplusblock;
|
||||||
uint8_t DABAFblock;
|
uint8_t DABAFblock;
|
||||||
uint8_t eRTblock;
|
uint8_t eRTblock;
|
||||||
uint8_t doublecounter;
|
uint8_t doublecounter;
|
||||||
uint16_t doubletestfreq;
|
uint16_t doubletestfreq;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user