Skip to content

Instantly share code, notes, and snippets.

@vladkorotnev
Created August 23, 2018 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladkorotnev/5ae32f9da64168882a0d1699daf62d6d to your computer and use it in GitHub Desktop.
Save vladkorotnev/5ae32f9da64168882a0d1699daf62d6d to your computer and use it in GitHub Desktop.
Patch for purple-vk-plugin (https://bitbucket.org/olegoandreev/purple-vk-plugin) to send smileys as HTML entity and avoid server-side emoji auto-substitute. Screenshot: http://i.imgur.com/llQ5npd.png
*** src/vk-smileys.orig.cpp 2018-08-23 21:07:33.069290031 +0500
--- src/vk-smileys.cpp 2018-08-23 21:06:30.741934284 +0500
***************
*** 1,7 ****
#include <fstream>
#include <glib.h>
#include <util.h>
!
#include <cpputils/trie.h>
#include "miscutils.h"
--- 1,8 ----
#include <fstream>
#include <glib.h>
#include <util.h>
! #include <stdio.h>
! #include <stdlib.h>
#include <cpputils/trie.h>
#include "miscutils.h"
***************
*** 206,214 ****
index++;
continue;
}
!
! message.replace(index, ascii_len, *unicode);
! index += unicode->length();
}
}
--- 207,234 ----
index++;
continue;
}
! if(ascii_len == 1) {
! // Seems it's an emoji, pass-through
! message.replace(index, ascii_len, *unicode);
! index += unicode->length();
! } else {
! string ascii = message.substr(index, ascii_len);
!
! string htmlentity = "";
!
! for(size_t i = 0; i < ascii.length(); i++) {
! htmlentity = htmlentity + "&#";
! char cur = ascii.at(i);
! char intStr[10];
! sprintf(intStr, "%d", cur);
! htmlentity = htmlentity + string(intStr);
! htmlentity = htmlentity + ";";
! }
!
! message.replace(index, ascii_len, htmlentity);
! index += htmlentity.length();
! }
!
}
}
@vladkorotnev
Copy link
Author

If somebody could please check this for memory leaks, that would be much appreciated! I never wrote any C++ before :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment