summaryrefslogtreecommitdiff
path: root/MirOTR/entities.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'MirOTR/entities.cpp')
-rw-r--r--MirOTR/entities.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/MirOTR/entities.cpp b/MirOTR/entities.cpp
index c757b70..892681b 100644
--- a/MirOTR/entities.cpp
+++ b/MirOTR/entities.cpp
@@ -393,3 +393,35 @@ size_t decode_html_entities_utf8(char *dest, const char *src, size_t len)
*to = 0;
return (size_t)(to - dest);
}
+
+char * encode_html_entities_utf8(const char *src) {
+ const char *pos, *start=src;
+ std::string buf;
+ if (! (pos = strpbrk(start, "&<>\"\r")) ) return NULL;
+ while (pos) {
+ buf.append(start, pos-start);
+ start = pos+1;
+ switch (*pos) {
+ case '"':
+ buf.append("&quot;");
+ break;
+ case '<':
+ buf.append("&lt;");
+ break;
+ case '>':
+ buf.append("&gt;");
+ break;
+ case '&':
+ buf.append("&amp;");
+ break;
+ case '\r':
+ buf.append("<br>\r");
+ break;
+ }
+ pos = strpbrk(start, "&<>\"\r");
+ }
+ if (strlen(start)) buf.append(start);
+ pos = mir_strdup(buf.c_str());
+ buf.clear();
+ return (char*)pos;
+} \ No newline at end of file