Made code in Connection::get_new_events() clearer.

This commit is contained in:
tastytea 2020-01-11 22:16:37 +01:00
parent a6b328c2d1
commit 1a99e8a276
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07

View File

@ -99,7 +99,8 @@ vector<event_type> Connection::get_new_events()
vector<event_type> events; vector<event_type> events;
size_t pos{0}; size_t pos{0};
while ((pos = buffer.find("event: ")) != string::npos) constexpr string_view search_event{"event: "};
while ((pos = buffer.find(search_event)) != string::npos)
{ {
const auto endpos{buffer.find("\n\n", pos)}; const auto endpos{buffer.find("\n\n", pos)};
if (endpos == string::npos) if (endpos == string::npos)
@ -108,9 +109,10 @@ vector<event_type> Connection::get_new_events()
} }
event_type event; event_type event;
pos += 7; // Length of "event: ". pos += search_event.size();
event.type = buffer.substr(pos, buffer.find('\n', pos) - pos); event.type = buffer.substr(pos, buffer.find('\n', pos) - pos);
pos = buffer.find("data: ") + 6; constexpr string_view search_data{"data: "};
pos = buffer.find(search_data) + search_data.size();
event.data = buffer.substr(pos, endpos - pos); event.data = buffer.substr(pos, endpos - pos);
events.push_back(event); events.push_back(event);