forked from CobaltFusion/DebugViewPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewlineFilter.cpp
More file actions
68 lines (60 loc) · 1.99 KB
/
Copy pathNewlineFilter.cpp
File metadata and controls
68 lines (60 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// (C) Copyright Gert-Jan de Vos and Jan Wilmans 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "CobaltFusion/stringbuilder.h"
#include "DebugViewppLib/LogSource.h"
#include "DebugViewppLib/ProcessInfo.h"
#include "DebugViewppLib/NewlineFilter.h"
#include <iostream>
namespace fusion {
namespace debugviewpp {
Lines NewlineFilter::Process(const Line& line)
{
auto& message = m_lineBuffers[line.pid];
message.reserve(512);
Lines lines;
for (auto c : line.message)
{
if (c == '\r')
{
continue;
}
if (c == '\n')
{
Line outputLine(line.time, line.systemTime, line.pid, line.processName, "", line.pLogSource);
std::swap(outputLine.message, message);
lines.emplace_back(std::move(outputLine));
}
else
{
message.push_back(c);
}
}
if (!message.empty())
{
if (line.pLogSource->GetAutoNewLine() || message.size() > 8192) // 8k line limit prevents stack overflow in handling code
{
Line outputLine(line.time, line.systemTime, line.pid, line.processName, "", line.pLogSource);
std::swap(outputLine.message, message);
lines.emplace_back(std::move(outputLine));
}
}
return lines;
}
Lines NewlineFilter::FlushLinesFromTerminatedProcess(DWORD pid, HANDLE /*handle*/) // todo: why is handle unused?
{
Lines lines;
if (m_lineBuffers.find(pid) != m_lineBuffers.end())
{
if (!m_lineBuffers[pid].empty())
{
// timestamp not filled, this will be done by the loopback source
lines.push_back(Line(0, FILETIME(), pid, "<flush>", m_lineBuffers[pid], nullptr));
}
m_lineBuffers.erase(pid);
}
return lines;
}
} // namespace debugviewpp
} // namespace fusion