summaryrefslogtreecommitdiff
path: root/MySpace/NetMessage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'MySpace/NetMessage.cpp')
-rw-r--r--MySpace/NetMessage.cpp46
1 files changed, 5 insertions, 41 deletions
diff --git a/MySpace/NetMessage.cpp b/MySpace/NetMessage.cpp
index 4db627a..d539132 100644
--- a/MySpace/NetMessage.cpp
+++ b/MySpace/NetMessage.cpp
@@ -1,5 +1,6 @@
#include "common.h"
#include "NetMessage.h"
+#include "formatting.h"
#include <cstdlib>
NMString::NMString(): text(0), len(-1) {
@@ -282,51 +283,14 @@ int Dictionary::make_body(char *buff, int size) {
char *Dictionary::escape(char *val) {
int len = strlen(val);
- char *buff = new char[len * 6 + 1];
- int read_pos = 0, write_pos = 0;
- while(read_pos < len) {
- if(val[read_pos] == '\'') {
- strncpy(buff + write_pos, "&#39;", 5);
- write_pos += 5;
- read_pos++;
- } else if(val[read_pos] == '`') {
- strncpy(buff + write_pos, "&#39;", 5);
- write_pos += 5;
- read_pos++;
- } else if(val[read_pos] == '#') {
- strncpy(buff + write_pos, "&#035;", 6);
- write_pos += 6;
- read_pos++;
- } else if(val[read_pos] == '\"') {
- strncpy(buff + write_pos, "&quot;", 6);
- write_pos += 6;
- read_pos++;
- } else {
- buff[write_pos++] = val[read_pos++];
- }
- }
- buff[write_pos] = 0;
+ char *buff = new char[len * 10 + 1]; // allow for every char to be a large html entity (e.g. '&thetasym;' is 10 chars!)
+ strcpy(buff, val);
+ entitize_html(buff, len * 10 + 1);
return buff;
}
char *Dictionary::unescape_inplace(char *val) {
- int read_pos = 0, write_pos = 0, len = strlen(val);
- while(read_pos < len) {
- if(read_pos + 5 < len && strncmp(&val[read_pos], "&#39;", 5) == 0) {
- read_pos += 5;
- val[write_pos++] = '\'';
- } else if(read_pos + 6 < len && strncmp(&val[read_pos], "&#035;", 6) == 0) {
- read_pos += 6;
- val[write_pos++] = '#';
- } else if(read_pos + 6 < len && strncmp(&val[read_pos], "&quot;", 6) == 0) {
- read_pos += 6;
- val[write_pos++] = '\"';
- } else {
- val[write_pos++] = val[read_pos++];
- }
- }
- val[write_pos] = 0;
-
+ unentitize_html(val);
return val;
}