Skip to content

Commit

Permalink
Remove convertAsciiToUtf8()
Browse files Browse the repository at this point in the history
  • Loading branch information
orempel committed Nov 30, 2023
1 parent 1cc73ce commit f94377f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 57 deletions.
4 changes: 1 addition & 3 deletions src/AudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,10 @@ uint32_t AudioPlayer_GetFileDuration(void) {
}

void Audio_setTitle(const char *format, ...) {
char buf[256];
va_list args;
va_start(args, format);
vsnprintf(buf, sizeof(buf) / sizeof(buf[0]), format, args);
vsnprintf(gPlayProperties.title, sizeof(gPlayProperties.title) / sizeof(gPlayProperties.title[0]), format, args);
va_end(args);
convertAsciiToUtf8(buf, gPlayProperties.title);

// notify web ui and mqtt
Web_SendWebsocketData(0, 30);
Expand Down
43 changes: 0 additions & 43 deletions src/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,6 @@ inline void convertFilenameToAscii(String utf8String, char *asciiString) {
asciiString[utf8String.length()] = 0;
}

inline void convertAsciiToUtf8(String asciiString, char *utf8String) {

int k = 0;

for (int i = 0; i < asciiString.length() && k < MAX_FILEPATH_LENTGH - 2; i++) {

switch (asciiString[i]) {
case 0x8e:
utf8String[k++] = 0xc3;
utf8String[k++] = 0x84;
break; // Ä
case 0x84:
utf8String[k++] = 0xc3;
utf8String[k++] = 0xa4;
break; // ä
case 0x9a:
utf8String[k++] = 0xc3;
utf8String[k++] = 0x9c;
break; // Ü
case 0x81:
utf8String[k++] = 0xc3;
utf8String[k++] = 0xbc;
break; // ü
case 0x99:
utf8String[k++] = 0xc3;
utf8String[k++] = 0x96;
break; // Ö
case 0x94:
utf8String[k++] = 0xc3;
utf8String[k++] = 0xb6;
break; // ö
case 0xe1:
utf8String[k++] = 0xc3;
utf8String[k++] = 0x9f;
break; // ß
default:
utf8String[k++] = asciiString[i];
}
}

utf8String[k] = 0;
}

// Release previously allocated memory
inline void freeMultiCharArray(char **arr, const uint32_t cnt) {
for (uint32_t i = 0; i < cnt; i++) {
Expand Down
15 changes: 4 additions & 11 deletions src/Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,12 +1304,9 @@ void explorerHandleListRequest(AsyncWebServerRequest *request) {
String MyfileName = root.getNextFileName(&isDir);
while (MyfileName != "") {
// ignore hidden folders, e.g. MacOS spotlight files
if (!startsWith(MyfileName.c_str(), (char *) "/.")) {
if (!MyfileName.startsWith("/.")) {
JsonObject entry = obj.createNestedObject();
convertAsciiToUtf8(MyfileName.c_str(), filePath);
std::string path = filePath;
std::string fileName = path.substr(path.find_last_of("/") + 1);
entry["name"] = fileName;
entry["name"] = MyfileName.substring(MyfileName.lastIndexOf('/') + 1);
if (isDir) {
entry["dir"].set(true);
}
Expand Down Expand Up @@ -1836,12 +1833,8 @@ void Web_DumpSdToNvs(const char *_filename) {
nvsEntry[0].nvsKey[strlen(token)] = '\0';
} else {
count = false;
if (isUtf8) {
memcpy(nvsEntry[0].nvsEntry, token, strlen(token));
nvsEntry[0].nvsEntry[strlen(token)] = '\0';
} else {
convertAsciiToUtf8(String(token), nvsEntry[0].nvsEntry);
}
memcpy(nvsEntry[0].nvsEntry, token, strlen(token));
nvsEntry[0].nvsEntry[strlen(token)] = '\0';
}
token = strtok(NULL, stringOuterDelimiter);
}
Expand Down

0 comments on commit f94377f

Please sign in to comment.