summaryrefslogtreecommitdiff
path: root/src/modules/filters/utf8html.cpp
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:49 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:49 -0400
commit8c8aa6b07e595cfac56838b5964ab3e96051f1b2 (patch)
treeda38e2c1979148dbd3b0c7b87f930746f5ba7f44 /src/modules/filters/utf8html.cpp
parent8d3fc864d094eeadc721f8e93436b37a5fab173e (diff)
Imported Upstream version 1.5.7
Diffstat (limited to 'src/modules/filters/utf8html.cpp')
-rw-r--r--src/modules/filters/utf8html.cpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/modules/filters/utf8html.cpp b/src/modules/filters/utf8html.cpp
index 7487815..94fbdc1 100644
--- a/src/modules/filters/utf8html.cpp
+++ b/src/modules/filters/utf8html.cpp
@@ -1,6 +1,6 @@
/******************************************************************************
*
- * utf8html - SWFilter decendant to convert a UTF-8 stream to HTML escapes
+ * utf8html - SWFilter descendant to convert a UTF-8 stream to HTML escapes
*
*/
@@ -9,29 +9,32 @@
#include <stdio.h>
#include <utf8html.h>
+SWORD_NAMESPACE_START
+
UTF8HTML::UTF8HTML() {
}
-char UTF8HTML::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
+char UTF8HTML::processText(SWBuf &text, const SWKey *key, const SWModule *module)
{
- unsigned char *to, *from;
+ unsigned char *from;
int len;
char digit[10];
unsigned long ch;
+ if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering
+ return -1;
+
+ len = strlenw(text.c_str()) + 2; // shift string to right of buffer
+
+ SWBuf orig = text;
+ from = (unsigned char *)orig.c_str();
- len = strlenw(text) + 2; // shift string to right of buffer
- if (len < maxlen) {
- memmove(&text[maxlen - len], text, len);
- from = (unsigned char*)&text[maxlen - len];
- }
- else from = (unsigned char*)text;
// -------------------------------
- for (to = (unsigned char*)text; *from; from++) {
+ for (text = ""; *from; from++) {
ch = 0;
if ((*from & 128) != 128) {
// if (*from != ' ')
- *to++ = *from;
+ text += *from;
continue;
}
if ((*from & 128) && ((*from & 64) != 64)) {
@@ -53,14 +56,14 @@ char UTF8HTML::ProcessText(char *text, int maxlen, const SWKey *key, const SWMod
ch |= (((short)*from) << (((6*subsequent)+significantFirstBits)-8));
from += subsequent;
- *to++ = '&';
- *to++ = '#';
+ text += '&';
+ text += '#';
sprintf(digit, "%d", ch);
for (char *dig = digit; *dig; dig++)
- *to++ = *dig;
- *to++ = ';';
+ text += *dig;
+ text += ';';
}
- *to++ = 0;
- *to = 0;
return 0;
}
+
+SWORD_NAMESPACE_END