[sword-svn] r3689 - in trunk: include src/modules/filters

scribe at crosswire.org scribe at crosswire.org
Fri Jan 31 18:36:20 MST 2020


Author: scribe
Date: 2020-01-31 18:36:20 -0700 (Fri, 31 Jan 2020)
New Revision: 3689

Modified:
   trunk/include/utf8nfkd.h
   trunk/src/modules/filters/utf8nfkd.cpp
Log:
updated to unorm2 methods to remove deprecation use


Modified: trunk/include/utf8nfkd.h
===================================================================
--- trunk/include/utf8nfkd.h	2020-02-01 00:57:28 UTC (rev 3688)
+++ trunk/include/utf8nfkd.h	2020-02-01 01:36:20 UTC (rev 3689)
@@ -25,18 +25,12 @@
 
 #include <swfilter.h>
 
-#include <unicode/utypes.h>
-#include <unicode/ucnv.h>
-#include <unicode/uchar.h>
-#include <unicode/unorm.h>
-
 SWORD_NAMESPACE_START
 
+struct UTF8NFKDPrivate;
 class SWDLLEXPORT UTF8NFKD : public SWFilter {
 private:
-	UConverter* conv;
-	UChar *source, *target;
-	UErrorCode err;
+	struct UTF8NFKDPrivate *p;
 public:
 	UTF8NFKD();
 	~UTF8NFKD();  

Modified: trunk/src/modules/filters/utf8nfkd.cpp
===================================================================
--- trunk/src/modules/filters/utf8nfkd.cpp	2020-02-01 00:57:28 UTC (rev 3688)
+++ trunk/src/modules/filters/utf8nfkd.cpp	2020-02-01 01:36:20 UTC (rev 3689)
@@ -26,22 +26,36 @@
 #include <utf8nfkd.h>
 #include <swbuf.h>
 
+#include <unicode/utypes.h>
+#include <unicode/ucnv.h>
+#include <unicode/uchar.h>
+#include <unicode/ustring.h>
+#include <unicode/unorm2.h>
 
+
 SWORD_NAMESPACE_START
 
+struct UTF8NFKDPrivate {
+	const UNormalizer2 *conv;
+};
 
 UTF8NFKD::UTF8NFKD() {
-        conv = ucnv_open("UTF-8", &err);
+	UErrorCode err = U_ZERO_ERROR;
+	p = new struct UTF8NFKDPrivate;
+	p->conv = unorm2_getNFKDInstance(&err);
 }
 
 
 UTF8NFKD::~UTF8NFKD() {
-         ucnv_close(conv);
+	delete p;
 }
 
 
 char UTF8NFKD::processText(SWBuf &text, const SWKey *key, const SWModule *module)
 {
+	UErrorCode err = U_ZERO_ERROR;
+	UChar *source, *target;
+
 	if ((unsigned long)key < 2)	// hack, we're en(1)/de(0)ciphering
 		return -1;
         
@@ -49,18 +63,21 @@
         source = new UChar[len + 1]; //each char could become a surrogate pair
 
 	// Convert UTF-8 string to UTF-16 (UChars)
-        int32_t ulen = ucnv_toUChars(conv, source, len, text.c_str(), -1, &err);
+	int32_t ulen;
+	u_strFromUTF8(source, len, &ulen, text.c_str(), (int32_t)text.size(), &err);
+
+
         target = new UChar[len + 1];
 
         //compatability decomposition
-        ulen = unorm_normalize(source, ulen, UNORM_NFKD, 0, target, len, &err);
+        ulen = unorm2_normalize(p->conv, source, ulen, target, len, &err);
 
-	   text.setSize(len);
-	   len = ucnv_fromUChars(conv, text.getRawData(), len, target, ulen, &err);
-	   text.setSize(len);
+	text.setSize(len);
+	u_strToUTF8 (text.getRawData(), len, &len, target, ulen, &err);
+	text.setSize(len);
 
-	   delete [] source;
-	   delete [] target;
+	delete [] source;
+	delete [] target;
 
 	return 0;
 }




More information about the sword-cvs mailing list