diff options
author | B Stack <bgstack15@gmail.com> | 2020-02-15 11:50:31 -0500 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-02-15 11:50:31 -0500 |
commit | 791b90b9898cc41869538f1dfc303588436682b7 (patch) | |
tree | 02cc7f817d95ce3f21207cbaba130e3d537fc1eb /zen/error_log.h | |
parent | Merge branch '10.19' into 'master' (diff) | |
download | FreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.tar.gz FreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.tar.bz2 FreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.zip |
add upstream 10.20
It is worth noting that the send email feature is not present in the
GPL release.
Diffstat (limited to 'zen/error_log.h')
-rw-r--r-- | zen/error_log.h | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/zen/error_log.h b/zen/error_log.h index 5115e6ef..cc52fc6e 100644 --- a/zen/error_log.h +++ b/zen/error_log.h @@ -10,9 +10,10 @@ #include <cassert> #include <algorithm> #include <vector> -#include <string> +//#include <string> #include "time.h" #include "i18n.h" +#include "utf.h" #include "zstring.h" @@ -30,7 +31,7 @@ struct LogEntry { time_t time = 0; MessageType type = MSG_TYPE_FATAL_ERROR; - Zstringw message; //std::wstring may employ small string optimization: we cannot accept bloating the "ErrorLog::entries" memory block below (think 1 million items) + Zstringw message; //std::wstring may employ small string optimization: we cannot accept bloating the "ErrorLog::entries_" memory block below (think 1 million items) }; std::wstring formatMessage(const LogEntry& entry); @@ -71,17 +72,14 @@ void ErrorLog::logMsg(const std::wstring& msg, MessageType type) inline int ErrorLog::getItemCount(int typeFilter) const { - return static_cast<int>(std::count_if(entries_.begin(), entries_.end(), [&](const LogEntry& e) { return e.type & typeFilter; })); + return static_cast<int>(std::count_if(entries_.begin(), entries_.end(), [typeFilter](const LogEntry& e) { return e.type & typeFilter; })); } -namespace +inline +std::wstring getMessageTypeLabel(MessageType type) { -std::wstring formatMessageImpl(const LogEntry& entry) -{ - auto getTypeName = [&] - { - switch (entry.type) + switch (type) { case MSG_TYPE_INFO: return _("Info"); @@ -94,32 +92,33 @@ std::wstring formatMessageImpl(const LogEntry& entry) } assert(false); return std::wstring(); - }; +} + + +inline +std::wstring formatMessage(const LogEntry& entry) +{ + std::wstring msgFmt = L"[" + formatTime<std::wstring>(FORMAT_TIME, getLocalTime(entry.time)) + L"] " + getMessageTypeLabel(entry.type) + L": "; + const size_t prefixLen = unicodeLength(msgFmt); //consider Unicode! - std::wstring msgFmt = L"[" + formatTime<std::wstring>(FORMAT_TIME, getLocalTime(entry.time)) + L"] " + getTypeName() + L": "; - const size_t prefixLen = msgFmt.size(); //considers UTF-16 only! + const Zstringw msg = trimCpy(entry.message); + static_assert(std::is_same_v<decltype(msg), const Zstringw>, "don't worry about copying as long as we're using a ref-counted string!"); - for (auto it = entry.message.begin(); it != entry.message.end(); ) + for (auto it = msg.begin(); it != msg.end(); ) if (*it == L'\n') { msgFmt += L'\n'; msgFmt.append(prefixLen, L' '); - - do //skip duplicate newlines - { - ++it; - } - while (it != entry.message.end() && *it == L'\n'); + ++it; + //skip duplicate newlines + for (;it != msg.end() && *it == L'\n'; ++it) + ; } else msgFmt += *it++; - return msgFmt; -} + return msgFmt += L'\n'; } - -inline -std::wstring formatMessage(const LogEntry& entry) { return formatMessageImpl(entry); } } #endif //ERROR_LOG_H_8917590832147915 |