Skip to content

Commit

Permalink
[PC] merge string_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
a8jan committed Nov 9, 2023
1 parent c811c51 commit 4521132
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
7 changes: 4 additions & 3 deletions fujinet_pc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions lib/utils/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <sstream>
#include <iomanip>

#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)
{
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -533,4 +537,4 @@ namespace mstr {
// parent = streamFile->url;
return parent + "/" + plus;
}
}
}
3 changes: 2 additions & 1 deletion lib/utils/string_utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef STRING_UTILS_H
#define STRING_UTILS_H

#include <cstdint>
#include <string>
#include <string_view>

Expand Down Expand Up @@ -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
#endif // STRING_UTILS_H
10 changes: 6 additions & 4 deletions pc_merge_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4521132

Please sign in to comment.