diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-02-22 21:37:35 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-02-22 21:37:35 +0300 |
commit | 24e0a7941965b6130fa008c0783d559c57c91005 (patch) | |
tree | e6f173f00ecdaa58a9b23fc38fb4a7bc1f0150c0 /src/chatlogger.cpp | |
parent | 1547aee3088cab359ac16f884dcd65a6770925ea (diff) | |
download | manaplus-24e0a7941965b6130fa008c0783d559c57c91005.tar.gz manaplus-24e0a7941965b6130fa008c0783d559c57c91005.tar.bz2 manaplus-24e0a7941965b6130fa008c0783d559c57c91005.tar.xz manaplus-24e0a7941965b6130fa008c0783d559c57c91005.zip |
Add const and some other minor changes in chatlogger and client classes.
Diffstat (limited to 'src/chatlogger.cpp')
-rw-r--r-- | src/chatlogger.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index 83292411e..7fd3a6509 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -88,8 +88,9 @@ void ChatLogger::setLogDir(const std::string &logDir) void ChatLogger::log(std::string str) { - std::string dateStr = getDir(); - std::string logFileName = strprintf("%s/#General.log", dateStr.c_str()); + const std::string &dateStr = getDir(); + const std::string logFileName = strprintf( + "%s/#General.log", dateStr.c_str()); if (!mLogFile.is_open() || logFileName != mLogFileName) { setLogDir(dateStr); @@ -102,8 +103,8 @@ void ChatLogger::log(std::string str) void ChatLogger::log(std::string name, std::string str) { - std::string dateStr = getDir(); - std::string logFileName = strprintf("%s/%s.log", + const std::string &dateStr = getDir(); + const std::string logFileName = strprintf("%s/%s.log", dateStr.c_str(), secureName(name).c_str()); if (!mLogFile.is_open() || logFileName != mLogFileName) @@ -121,11 +122,10 @@ std::string ChatLogger::getDir() const std::string date; time_t rawtime; - struct tm *timeinfo; char buffer [81]; time (&rawtime); - timeinfo = localtime(&rawtime); + struct tm *const timeinfo = localtime(&rawtime); strftime(buffer, 79, "%Y-%m/%d", timeinfo); @@ -137,15 +137,16 @@ std::string ChatLogger::getDir() const std::string ChatLogger::secureName(std::string &name) const { - for (unsigned int f = 0; f < name.length(); f ++) + for (unsigned int f = 0, sz = name.length(); f < sz; f ++) { - if ((name[f] < '0' || name[f] > '9') - && (name[f] < 'a' || name[f] > 'z') - && (name[f] < 'A' || name[f] > 'Z') - && name[f] != '-' && name[f] != '+' && name[f] != '=' - && name[f] != '.' && name[f] != ',' && name[f] != ')' - && name[f] != '(' && name[f] != '[' && name[f] != ']' - && name[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 != '#') { name[f] = '_'; } |