void ChatControlMessageText::splitMessage(WhatsappMessage &message) { std::string messageString = message.getData(); int lastSplit = 0; for (std::string::iterator it = messageString.begin(); it != messageString.end();) { bool begin = (it - messageString.begin()) == lastSplit; std::string::iterator before = it; int character = utf8::next(it, messageString.end()); if (isSmiley(character)) { if (!begin) { int start = lastSplit; int end = before - messageString.begin(); std::string leftPart = messageString.substr(start, end - start); elements.push_back(new ChatControlMessageElement(leftPart)); } elements.push_back(new ChatControlMessageElement(character)); lastSplit = (it - messageString.begin()); } } int length = messageString.length(); if (lastSplit < length) { std::string part = messageString.substr(lastSplit, length); elements.push_back(new ChatControlMessageElement(part)); } }
std::string ChatExporterHtml::convertMessageToHtml(WhatsappMessage &message, std::set<int> &usedEmoticons) { std::string messageString = message.getData(); std::stringstream output; try { for (std::string::iterator it = messageString.begin(); it != messageString.end();) { std::string::iterator before = it; int character = utf8::next(it, messageString.end()); if (isSmiley(character)) { usedEmoticons.insert(character); output << "<span class=\"emoticon_" << std::hex << character << "\"></span>"; } else { output << std::string(before, it); } } } catch (utf8::exception &exception) { output << "[INVALID DATA: " << messageString << "]"; } return output.str(); }