diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-29 11:21:34 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-29 14:18:06 +0100 |
commit | 59ee2d9dc81b2ed89f073b1541fc8d8c4f1f28f8 (patch) | |
tree | 3dd041393b8340a6d1e59aed5c70e2a056f72c33 /src/chatlogger.cpp | |
parent | e7c285e3423ddd660447f6a6fc6bbae25f99f386 (diff) | |
download | mana-59ee2d9dc81b2ed89f073b1541fc8d8c4f1f28f8.tar.gz mana-59ee2d9dc81b2ed89f073b1541fc8d8c4f1f28f8.tar.bz2 mana-59ee2d9dc81b2ed89f073b1541fc8d8c4f1f28f8.tar.xz mana-59ee2d9dc81b2ed89f073b1541fc8d8c4f1f28f8.zip |
Updated ChatLogger::secureName to fixed version
Using the latest implementation from ManaPlus. Previous version was
introduced with 844e9a7a72faca6a212e788a3adc45e17f41dca6 and failed to
"secure" the name due to broken conditions.
Diffstat (limited to 'src/chatlogger.cpp')
-rw-r--r-- | src/chatlogger.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index e126b0ef..904da133 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -124,17 +124,27 @@ std::string ChatLogger::getDateString() const return date; } -std::string ChatLogger::secureName(std::string &name) const +std::string ChatLogger::secureName(std::string &name) { - for (char & f : name) + const size_t sz = name.length(); + for (size_t f = 0; f < sz; f ++) { - if (f < '0' && f > '9' && f < 'a' && f > 'z' - && f < 'A' && f > 'Z' - && f != '-' && f != '+' && f != '=' - && f != '.' && f != ','&& f != ')' - && f != '(' && f != '[' && f != ')') + const unsigned char ch = name[f]; + if ((ch < '0' || ch > '9') && + (ch < 'a' || ch > 'z') && + (ch < 'A' || ch > 'Z') && + ch != '-' && + ch != '+' && + ch != '=' && + ch != '.' && + ch != ',' && + ch != ')' && + ch != '(' && + ch != '[' && + ch != ']' && + ch != '#') { - f = '_'; + name[f] = '_'; } } return name; |