summaryrefslogtreecommitdiff
path: root/src/modules/filters/utf8nfkd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/filters/utf8nfkd.cpp')
-rw-r--r--src/modules/filters/utf8nfkd.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/modules/filters/utf8nfkd.cpp b/src/modules/filters/utf8nfkd.cpp
index 450cbbf..6da24f8 100644
--- a/src/modules/filters/utf8nfkd.cpp
+++ b/src/modules/filters/utf8nfkd.cpp
@@ -1,13 +1,12 @@
/******************************************************************************
*
-* utf8nfkd - SWFilter decendant to perform NFKD (compatability decomposition
+* utf8nfkd - SWFilter descendant to perform NFKD (compatability decomposition
* normalization) on UTF-8 text
*/
#ifdef _ICU_
#include <stdlib.h>
-#include <string.h>
#ifdef __GNUC__
#include <unixstr.h>
@@ -15,6 +14,8 @@
#include <utf8nfkd.h>
+SWORD_NAMESPACE_START
+
UTF8NFKD::UTF8NFKD() {
conv = ucnv_open("UTF-8", &err);
}
@@ -23,24 +24,30 @@ UTF8NFKD::~UTF8NFKD() {
ucnv_close(conv);
}
-char UTF8NFKD::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
+char UTF8NFKD::processText(SWBuf &text, const SWKey *key, const SWModule *module)
{
- int32_t len = strlen(text) * 2;
+ if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering
+ return -1;
+
+ int32_t len = text.length() * 2;
source = new UChar[len + 1]; //each char could become a surrogate pair
// Convert UTF-8 string to UTF-16 (UChars)
- len = ucnv_toUChars(conv, source, len, text, -1, &err);
+ len = ucnv_toUChars(conv, source, len, text.c_str(), -1, &err);
target = new UChar[len + 1];
//compatability decomposition
unorm_normalize(source, len, UNORM_NFKD, 0, target, len, &err);
- ucnv_fromUChars(conv, text, maxlen, target, -1, &err);
+ text.setSize(text.size()*2);
+ len = ucnv_fromUChars(conv, text.getRawData(), text.size(), target, -1, &err);
+ text.setSize(len);
- delete [] source;
- delete [] target;
+ delete [] source;
+ delete [] target;
return 0;
}
+SWORD_NAMESPACE_END
#endif