From 5e1c2af819ea7987880f1ccc33da5ae20c6d8d9c Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Tue, 21 May 2024 13:06:43 +0200 Subject: [PATCH] Trim spaces at the end of RT when transmitter is not using 0x0d as end command --- src/TEF6686.cpp | 9 +++++++++ src/TEF6686.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index b24fff7..1ddf699 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -1167,6 +1167,7 @@ void TEF6686::readRDS(byte showrdserrors) { RDScharConverter(rt_buffer, RTtext, sizeof(RTtext) / sizeof(wchar_t), true); // Convert 8 bit ASCII to 16 bit ASCII rds.stationText = convertToUTF8(RTtext); // Convert RDS characterset to ASCII rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarker, true); // Make sure RT does not exceed 64 characters + rds.stationText = trimTrailingSpaces(rds.stationText); // Trim empty spaces at the end } for (byte i = 0; i < 64; i++) { @@ -1188,6 +1189,7 @@ void TEF6686::readRDS(byte showrdserrors) { RDScharConverter(rt_buffer, RTtext, sizeof(RTtext) / sizeof(wchar_t), true); // Convert 8 bit ASCII to 16 bit ASCII rds.stationText = convertToUTF8(RTtext); // Convert RDS characterset to ASCII rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarker, true); // Make sure RT does not exceed 64 characters + rds.stationText = trimTrailingSpaces(rds.stationText); // Trim empty spaces at the end } for (int i = 0; i < 64; i++) rt_buffer2[i] = rt_buffer[i]; @@ -1224,6 +1226,7 @@ void TEF6686::readRDS(byte showrdserrors) { RDScharConverter(rt_buffer32, RTtext, sizeof(RTtext) / sizeof(wchar_t), true); // Convert 8 bit ASCII to 16 bit ASCII rds.stationText32 = convertToUTF8(RTtext); // Convert RDS characterset to ASCII rds.stationText32 = extractUTF8Substring(rds.stationText32, 0, endmarker, true); // Make sure RT does not exceed 32 characters + rds.stationText = trimTrailingSpaces(rds.stationText); // Trim empty spaces at the end } } break; @@ -1925,4 +1928,10 @@ void TEF6686::RDScharConverter(const char* input, wchar_t* output, size_t size, } } output[size - 1] = L'\0'; +} + +String TEF6686::trimTrailingSpaces(String str) { + int end = str.length() - 1; + while (end >= 0 && isspace(str[end])) end--; + return str.substring(0, end + 1); } \ No newline at end of file diff --git a/src/TEF6686.h b/src/TEF6686.h index fcdaa24..5c92d9f 100644 --- a/src/TEF6686.h +++ b/src/TEF6686.h @@ -718,6 +718,7 @@ class TEF6686 { void RDScharConverter(const char* input, wchar_t* output, size_t size, bool under); String convertToUTF8(const wchar_t* input); String extractUTF8Substring(const String& utf8String, size_t start, size_t length, bool under); + String trimTrailingSpaces(String str); char ps_buffer[9]; char ps_buffer2[9]; char ptyn_buffer[9];