Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Aug 23, 2018

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
You can’t perform that action at this time.