summaryrefslogtreecommitdiff
path: root/zen/error_log.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <shieldwed@outlook.com>2020-02-23 22:12:27 +0000
committerDaniel Wilhelm <shieldwed@outlook.com>2020-02-23 22:12:27 +0000
commit450f803dd75f831f8ee14072fe0eb664bbe518df (patch)
treeb3e831d44df50348a20f3541b6062f7fbab6ff3d /zen/error_log.h
parentMerge branch '10.19' into 'master' (diff)
parentremove upstream deleted files (diff)
downloadFreeFileSync-10.20.tar.gz
FreeFileSync-10.20.tar.bz2
FreeFileSync-10.20.zip
Merge branch '10.20' into 'master'10.20
add upstream 10.20 See merge request opensource-tracking/FreeFileSync!17
Diffstat (limited to 'zen/error_log.h')
-rw-r--r--zen/error_log.h47
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
bgstack15