MCPcopy Create free account
hub / github.com/WarmUpTill/SceneSwitcher / parseMessages

Function parseMessages

plugins/twitch/chat-connection.cpp:291–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289}
290
291static std::vector<IRCMessage> parseMessages(const std::string &messagesStr)
292{
293 static constexpr std::string_view delimiter = "\r\n";
294 std::vector<IRCMessage> messages;
295
296 auto isWhitespace = [](const std::string &str) -> bool {
297 for (char c : str) {
298 if (!std::isspace(static_cast<unsigned char>(c))) {
299 return false;
300 }
301 }
302 return true;
303 };
304
305 size_t start = 0;
306 size_t end = messagesStr.find(delimiter);
307 while (end != std::string::npos) {
308 auto message = messagesStr.substr(start, end - start);
309 if (isWhitespace(message)) {
310 continue;
311 }
312 auto parsedMessage = parseMessage(message);
313 if (parsedMessage.command.command.empty()) {
314 vblog(LOG_INFO, "discarding IRC message: %s",
315 message.c_str());
316 } else {
317 messages.emplace_back(parsedMessage);
318 }
319 start = end + delimiter.length();
320 end = messagesStr.find(delimiter, start);
321 }
322 auto message = messagesStr.substr(start);
323 if (isWhitespace(message)) {
324 return messages;
325 }
326 auto parsedMessage = parseMessage(message);
327 if (parsedMessage.command.command.empty()) {
328 vblog(LOG_INFO, "discarding IRC message: %s", message.c_str());
329 return messages;
330 }
331 messages.emplace_back(parsedMessage);
332 return messages;
333}
334
335/* ------------------------------------------------------------------------- */
336

Callers 1

OnMessageMethod · 0.85

Calls 6

parseMessageFunction · 0.85
findMethod · 0.80
substrMethod · 0.80
isWhitespaceFunction · 0.50
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected