From 4521132eae4a6fe9cc3db92c900c2a1a6cba4215 Mon Sep 17 00:00:00 2001 From: Jan Krupa Date: Thu, 9 Nov 2023 18:18:49 +0100 Subject: [PATCH] [PC] merge string_utils --- fujinet_pc.cmake | 7 ++++--- lib/utils/string_utils.cpp | 14 +++++++++----- lib/utils/string_utils.h | 3 ++- pc_merge_notes.md | 10 ++++++---- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/fujinet_pc.cmake b/fujinet_pc.cmake index 8bc88f270..b972fff8b 100644 --- a/fujinet_pc.cmake +++ b/fujinet_pc.cmake @@ -86,9 +86,10 @@ set(SOURCES # lib/config/fnc_serial.cpp # lib/config/fnc_util.cpp # lib/config/fnc_wifi.cpp - include/debug.h lib/utils/utils.h lib/utils/utils.cpp -# lib/utils/cbuf.h lib/utils/cbuf.cpp -# lib/utils/string_utils.h lib/utils/string_utils.cpp + include/debug.h + lib/utils/utils.h lib/utils/utils.cpp + lib/utils/cbuf.h lib/utils/cbuf.cpp + lib/utils/string_utils.h lib/utils/string_utils.cpp # lib/hardware/fnWiFi.h lib/hardware/fnDummyWiFi.h lib/hardware/fnDummyWiFi.cpp # lib/hardware/led.h lib/hardware/led.cpp # lib/hardware/fnUART.h lib/hardware/fnUART.cpp diff --git a/lib/utils/string_utils.cpp b/lib/utils/string_utils.cpp index 94670cca6..415282988 100644 --- a/lib/utils/string_utils.cpp +++ b/lib/utils/string_utils.cpp @@ -10,6 +10,10 @@ #include #include +#if defined(_WIN32) +#include "asprintf.h" // use asprintf from libsmb2 +#endif + // Copy string to char buffer void copyString(const std::string& input, char *dst, size_t dst_size) { @@ -182,16 +186,16 @@ namespace mstr { unsigned int index; for (index = 0; index < s1.size(); index++) { - switch (s1[index]) { + switch ((unsigned char)s1[index]) { case '*': return true; /* rest is not interesting, it's a match */ case '?': - if (s2[index] == 0xa0) { + if ((unsigned char)s2[index] == 0xa0) { return false; /* wildcard, but the other is too short */ } break; case 0xa0: /* This one ends, let's see if the other as well */ - return (s2[index] == 0xa0); + return ((unsigned char)s2[index] == 0xa0); default: if (s1[index] != s2[index]) { return false; /* does not match */ @@ -234,7 +238,7 @@ namespace mstr { void A02Space(std::string &s) { std::transform(s.begin(), s.end(), s.begin(), - [](unsigned char c) { return (c == '\xA0') ? '\x20': c; }); + [](unsigned char c) { return (c == 0xa0) ? 0x20: c; }); } bool isText(std::string &s) @@ -533,4 +537,4 @@ namespace mstr { // parent = streamFile->url; return parent + "/" + plus; } -} \ No newline at end of file +} diff --git a/lib/utils/string_utils.h b/lib/utils/string_utils.h index 0eb9841ae..0ef9bde24 100644 --- a/lib/utils/string_utils.h +++ b/lib/utils/string_utils.h @@ -1,6 +1,7 @@ #ifndef STRING_UTILS_H #define STRING_UTILS_H +#include #include #include @@ -54,4 +55,4 @@ namespace mstr { std::string parent(std::string path, std::string plus = ""); std::string localParent(std::string path, std::string plus); } -#endif \ No newline at end of file +#endif // STRING_UTILS_H diff --git a/pc_merge_notes.md b/pc_merge_notes.md index 0b233cba5..548c6426f 100644 --- a/pc_merge_notes.md +++ b/pc_merge_notes.md @@ -36,11 +36,13 @@ - TODO: lib/config/fnc_wifi.cpp -- **DONE**: include/debug.h lib/utils/utils.h lib/utils/utils.cpp +- **DONE** / merged: include/debug.h -- TODO: lib/utils/cbuf.h lib/utils/cbuf.cpp +- **DONE** / merged: lib/utils/utils.h lib/utils/utils.cpp -- TODO: lib/utils/string_utils.h lib/utils/string_utils.cpp +- **DONE** / no change: lib/utils/cbuf.h lib/utils/cbuf.cpp + +- **WIP**: lib/utils/string_utils.h lib/utils/string_utils.cpp - TODO: lib/hardware/fnWiFi.h lib/hardware/fnDummyWiFi.h lib/hardware/fnDummyWiFi.cpp @@ -74,7 +76,7 @@ - TODO: lib/FileSystem/fnFileMem.h lib/FileSystem/fnFileMem.cpp -- **NO CHANGE**: lib/EdUrlParser/EdUrlParser.h lib/EdUrlParser/EdUrlParser.cpp +- **DONE** / no change: lib/EdUrlParser/EdUrlParser.h lib/EdUrlParser/EdUrlParser.cpp Note: So far the file compiles without errors. Maybe it will be necessary to use FN-PC version calling std namespace explicitly