Skip to content

Commit 8b0955c

Browse files
committed
Fix help table reference and example
1 parent 5250fdc commit 8b0955c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

deus-console.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ typedef std::function<std::string()> TDeusConsoleFuncToString;
7575
typedef std::function<void*()> TDeusConsoleFuncRead;
7676
typedef std::function<void(void*)> TDeusConsoleFuncVoid;
7777
typedef std::function<void(char*)> TDeusConsoleFuncWriteChar;
78-
typedef std::unordered_map<const char*, const char*> DeusConsoleHelpTable;
78+
typedef std::unordered_map<std::string, std::string> DeusConsoleHelpTable;
7979

8080
// Wrapper for console variables and their flags/methods
8181
struct DeusConsoleVariable {
@@ -196,7 +196,7 @@ class IDeusConsoleManager {
196196
}
197197

198198
// Returns a reference to the help table itself, useful for iterating over potential cmds
199-
std::unordered_map<std::string, std::string>& getHelpTable() {
199+
DeusConsoleHelpTable& getHelpTable() {
200200
return this->helpTable;
201201
}
202202

example/main.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ inline void processCommand(char* cmd) {
8888
}
8989
}
9090

91-
// Compare strings by n
92-
inline static int compareStrs(const char *s1, const char *s2, int n) {
91+
// Compare two strings (case-insensitive) up to n characters
92+
inline static int compareStrs(const std::string& s1, const std::string& s2, int n) {
9393
int d = 0;
94-
while (n > 0 && (d = tolower(*s2) - tolower(*s1)) == 0 && *s1) {
95-
s1++;
96-
s2++;
97-
n--;
94+
int i = 0;
95+
while (i < n && (
96+
d = std::tolower(static_cast<unsigned char>(s2[i])) -
97+
std::tolower(static_cast<unsigned char>(s1[i]))
98+
) == 0 && i < static_cast<int>(s1.size())) {
99+
++i;
98100
}
99101
return d;
100102
}

0 commit comments

Comments
 (0)