-
Notifications
You must be signed in to change notification settings - Fork 574
/
Copy pathResponseParser.cpp
69 lines (58 loc) · 1.76 KB
/
ResponseParser.cpp
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
69
#include "stdafx.h"
#include <StringAlgorithm.hpp>
#include <WeaselIPC.h>
#include "Deserializer.h"
using namespace weasel;
ResponseParser::ResponseParser(std::wstring* commit,
Context* context,
Status* status,
Config* config,
UIStyle* style)
: p_commit(commit),
p_context(context),
p_status(status),
p_config(config),
p_style(style) {
Deserializer::Initialize(this);
}
bool ResponseParser::operator()(LPWSTR buffer, UINT length) {
wbufferstream bs(buffer, length);
std::wstring line;
while (bs.good()) {
std::getline(bs, line);
if (!bs.good())
return false;
// file ends
if (line == L".")
break;
Feed(line);
}
return bs.good();
}
void ResponseParser::Feed(const std::wstring& line) {
// ignore blank lines and comments
if (line.empty() || line.find_first_of(L'#') == 0)
return;
Deserializer::KeyType key;
std::wstring value;
// extract key (split by L'.') and value
std::wstring::size_type sep_pos = line.find_first_of(L'=');
if (sep_pos == std::wstring::npos)
return;
split(key, line.substr(0, sep_pos), L".");
if (key.empty())
return;
value = line.substr(sep_pos + 1);
// first part of the key serve as action type
std::wstring const& action = key[0];
// get required action deserializer instance
std::map<std::wstring, Deserializer::Ptr>::iterator i =
deserializers.find(action);
if (i == deserializers.end()) {
// line ignored... since corresponding deserializer is not active
return;
}
// dispatch
Deserializer::Ptr p = i->second;
p->Store(key, value);
}