summaryrefslogtreecommitdiff
path: root/src/modules/filters/utf8arshaping.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/utf8arshaping.cpp
parent8d3fc864d094eeadc721f8e93436b37a5fab173e (diff)
Imported Upstream version 1.5.7
Diffstat (limited to 'src/modules/filters/utf8arshaping.cpp')
-rw-r--r--src/modules/filters/utf8arshaping.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/modules/filters/utf8arshaping.cpp b/src/modules/filters/utf8arshaping.cpp
index 5121f48..3246adc 100644
--- a/src/modules/filters/utf8arshaping.cpp
+++ b/src/modules/filters/utf8arshaping.cpp
@@ -1,13 +1,12 @@
/******************************************************************************
*
-* utf8arshaping - SWFilter decendant to perform Arabic shaping on
+* utf8arshaping - SWFilter descendant to perform Arabic shaping on
* UTF-8 text
*/
#ifdef _ICU_
#include <stdlib.h>
-#include <string.h>
#ifdef __GNUC__
#include <unixstr.h>
@@ -15,34 +14,39 @@
#include <utf8arshaping.h>
-UTF8arShaping::UTF8arShaping() {
-
- conv = ucnv_open("UTF-8", &err);
+SWORD_NAMESPACE_START
+UTF8arShaping::UTF8arShaping() {
+ conv = ucnv_open("UTF-8", &err);
}
UTF8arShaping::~UTF8arShaping() {
ucnv_close(conv);
}
-char UTF8arShaping::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
+char UTF8arShaping::processText(SWBuf &text, const SWKey *key, const SWModule *module)
{
UChar *ustr, *ustr2;
+ if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering
+ return -1;
- int32_t len = strlen(text);
+ int32_t len = text.length();
ustr = new UChar[len];
ustr2 = new UChar[len];
// Convert UTF-8 string to UTF-16 (UChars)
- len = ucnv_toUChars(conv, ustr, len, text, -1, &err);
+ len = ucnv_toUChars(conv, ustr, len, text.c_str(), -1, &err);
len = u_shapeArabic(ustr, len, ustr2, len, U_SHAPE_LETTERS_SHAPE | U_SHAPE_DIGITS_EN2AN, &err);
- ucnv_fromUChars(conv, text, maxlen, ustr2, len, &err);
+ text.setSize(text.size()*2);
+ len = ucnv_fromUChars(conv, text.getRawData(), text.size(), ustr2, len, &err);
+ text.setSize(len);
delete [] ustr2;
delete [] ustr;
return 0;
}
+SWORD_NAMESPACE_END
#endif