瀏覽代碼

using escape function to replace emojis with tokens

logicp 5 年之前
父節點
當前提交
3ce06ec942
共有 1 個文件被更改,包括 40 次插入0 次删除
  1. 40 0
      headers/util.hpp

+ 40 - 0
headers/util.hpp

@@ -43,6 +43,46 @@ struct KSession {
     int status;
 };
 
+static QString escapeText(QString s) {
+    qDebug() << "Escaping text";
+    if (s.contains("'")) {
+        qDebug() << "Replacing single quote";
+        s.replace("'", "'\"'\"'");
+    }
+    if (s.contains("\t")) {
+        s.replace("\t", "\\t");
+    }
+    if (s.contains("🙋‍♀️")) {
+        qDebug() << "Replacing woman raising hand emoji";
+        s.replace("🙋‍♀️", ":woman raising hand:");
+    }
+    if (s.contains("❤️")) {
+        qDebug() << "Replacing heart";
+        s.replace("❤️", ":heart:");
+    }
+    return s;
+}
+
+static QString escapeTextToRaw(QString s) {
+    qDebug() << "Escaping text";
+    if (s.contains("'")) {
+        qDebug() << "Replacing single quote";
+        s.replace("'", "'\"'\"'");
+    }
+    if (s.contains("\t")) {
+        s.replace("\t", "\\t");
+    }
+    if (s.contains("🙋‍♀️")) {
+        qDebug() << "Replacing woman raising hand emoji";
+        s.replace("🙋‍♀️", ":woman raising hand:");
+    }
+    if (s.contains("❤️")) {
+        qDebug() << "Replacing heart";
+        s.replace("❤️", ":heart:");
+    }
+    return s.toUtf8().constData();
+}
+
 std::string getJsonString(std::string s) {
     Document d;
     d.Parse(s.c_str());