diff --git a/include/znc/Utils.h b/include/znc/Utils.h index 2406653c..a644ed88 100644 --- a/include/znc/Utils.h +++ b/include/znc/Utils.h @@ -84,6 +84,9 @@ public: static CString FormatTime(time_t t, const CString& sFormat, const CString& sTZ); static SCString GetTimezones(); + static MCString GetMessageTags(const CString& sLine); + static void SetMessageTags(CString& sLine, const MCString& mssTags); + private: protected: }; diff --git a/src/Utils.cpp b/src/Utils.cpp index 2be58eb8..16bac4b5 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -459,6 +459,37 @@ SCString CUtils::GetTimezones() { return result; } +MCString CUtils::GetMessageTags(const CString& sLine) { + if (sLine.StartsWith("@")) { + VCString vsTags; + sLine.Token(0).TrimPrefix_n("@").Split(";", vsTags, false); + + MCString mssTags; + for (VCString::const_iterator it = vsTags.begin(); it != vsTags.end(); ++it) { + mssTags[it->Token(0, false, "=")] = it->Token(1, true, "="); + } + return mssTags; + } + return MCString::EmptyMap; +} + +void CUtils::SetMessageTags(CString& sLine, const MCString& mssTags) { + if (sLine.StartsWith("@")) { + sLine.LeftChomp(sLine.Token(0).length() + 1); + } + + if (!mssTags.empty()) { + CString sTags; + for (MCString::const_iterator it = mssTags.begin(); it != mssTags.end(); ++it) { + if (!sTags.empty()) { + sTags += ";"; + } + sTags += it->first + "=" + it->second; + } + sLine = "@" + sTags + " " + sLine; + } +} + bool CTable::AddColumn(const CString& sName) { for (unsigned int a = 0; a < m_vsHeaders.size(); a++) { if (m_vsHeaders[a].Equals(sName)) {