diff options
Diffstat (limited to 'MySpace/formatting.cpp')
-rw-r--r-- | MySpace/formatting.cpp | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/MySpace/formatting.cpp b/MySpace/formatting.cpp index 4b8669a..891f75e 100644 --- a/MySpace/formatting.cpp +++ b/MySpace/formatting.cpp @@ -5,7 +5,7 @@ void entitize(char *buff, int size) { char *tmp = new char[size];
int in = 0, out = 0;
- while(buff[in]) {
+ while(buff[in] && out < size) {
switch(buff[in]) {
case '\"': in++; strncpy(tmp + out, """, size - out); out += 6; break;
case '&': in++; strncpy(tmp + out, "&", size - out); out += 5; break;
@@ -48,7 +48,7 @@ void unentitize(char *buff) { void strip_tags(char *buff) {
int in = 0, out = 0;
while(buff[in]) {
- if(buff[in] == '<') {
+ if(buff[in] == '<' && buff[in + 1] != 'i') {
while(buff[in] && buff[in] != '>') in++;
in++;
} else
@@ -57,3 +57,74 @@ void strip_tags(char *buff) { buff[out] = 0;
}
+char *words[25] = {"bigsmile", "growl", "mad", "scared", "tongue", "devil", "happy", "messed", "sidefrown", "upset", "frazzled",
+ "heart", "nerd", "sinister", "wink", "geek", "laugh", "oops", "smirk", "worried", "googles", "mohawk", "pirate", "straight", "kiss"};
+char *symbols[25] = {":D", ":E", "X(", ":O", ":p", "}:)", ":)", "X)", ":{", "B|", ":Z",
+ ":X", "Q)", ":B", ";-)", "B)", ":))", ":G", ":,", ":[", "%)", "-:", "P)", ":|", ":X"};
+
+void encode_smileys(char *buff, int size) {
+ char *tmp = new char[size];
+
+ int in = 0, out = 0;
+ char sb[128];
+ bool done;
+ int i, len, len_s;
+ while(buff[in] && out < size) {
+ done = false;
+ for(i = 0; i < 25; i++) {
+ len_s = strlen(symbols[i]);
+ if(strncmp(buff + in, symbols[i], len_s) == 0) {
+ mir_snprintf(sb, 128, "<i n=\"%s\"/>", words[i]);
+ len = strlen(sb);
+ strncpy(tmp + out, sb, size - out);
+ out += len;
+ in += len_s;
+ done = true;
+ break;
+ }
+ }
+ if(!done) tmp[out++] = buff[in++];
+ }
+ tmp[out] = 0;
+
+ strncpy(buff, tmp, size);
+ delete tmp;
+ buff[size - 1] = 0;
+}
+
+void decode_smileys(char *buff) {
+ int in = 0, out = 0;
+ char sb[128];
+ bool done;
+ int i, j, len, len_s;
+ while(buff[in]) {
+ if(buff[in] == '<') {
+ done = false;
+ for(i = 0; i < 25; i++) {
+ mir_snprintf(sb, 128, "<i n=\"%s\"/>", words[i]);
+ len = strlen(sb);
+ if(strncmp(buff + in, sb, len) == 0) {
+ len_s = strlen(symbols[i]);
+ strncpy(buff + out, symbols[i], len_s);
+ out += len_s;
+ in += len;
+ done = true;
+ break;
+ }
+ mir_snprintf(sb, 128, "<i n='%s\'/>", words[i]);
+ if(strncmp(buff + in, sb, len) == 0) {
+ len_s = strlen(symbols[i]);
+ strncpy(buff + out, symbols[i], len_s);
+ out += len_s;
+ in += len;
+ done = true;
+ break;
+ }
+ }
+ if(!done) buff[out++] = buff[in++];
+ } else
+ buff[out++] = buff[in++];
+ }
+ buff[out] = 0;
+}
+
|