Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add CUtils::Get/SetMessageTags()

  • Loading branch information...
commit 5f8f7477044919cc7e4a0dafdfca98cf642e7d88 1 parent 0a0be77
J-P Nurmi jpnurmi authored
Showing with 34 additions and 0 deletions.
  1. +3 −0  include/znc/Utils.h
  2. +31 −0 src/Utils.cpp
3  include/znc/Utils.h
View
@@ -84,6 +84,9 @@ class CUtils {
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:
};
31 src/Utils.cpp
View
@@ -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)) {
Please sign in to comment.
Something went wrong with that request. Please try again.