summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Beckett <dave@dajobe.org>2020-09-13 06:52:17 -0700
committerDave Beckett <dave@dajobe.org>2020-09-13 06:52:17 -0700
commitac46bef64a7f9596a59b55386361d4c4b29d5329 (patch)
treee6ffc5b95314046003ffa2df86bdc987f64d70db
parentd5a6331ef703d404709c903066d12d5ef39bae7f (diff)
downloadraptor-ac46bef64a7f9596a59b55386361d4c4b29d5329.tar.gz
Use newer ICU NFC check for ICU V56 or newer
(raptor_nfc_icu_check): Switch to use unorm2_quickCheck() for ICU >= 56
-rw-r--r--configure.ac6
-rw-r--r--src/raptor_nfc_icu.c33
2 files changed, 36 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index c3fe26ba..401586e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -658,8 +658,10 @@ fi
PKG_CHECK_MODULES([ICU], [icu-uc], [
have_icu=yes
- ICU_VERSION=`$PKG_CONFIG icu-uc --modversion`
+ ICU_UC_VERSION=`$PKG_CONFIG icu-uc --modversion`
], [have_icu=no])
+ICU_UC_MAJOR_VERSION=`echo "$ICU_UC_VERSION" | sed -e 's/\..*$//'`
+AC_DEFINE_UNQUOTED(ICU_UC_MAJOR_VERSION, $ICU_UC_MAJOR_VERSION, [ICU UC major version])
AC_ARG_WITH(www-config, [ --with-libwww-config=PATH Location of W3C libwww libwww-config []], libwww_config="$withval", libwww_config="")
@@ -1175,7 +1177,7 @@ if test $need_icu = yes; then
CPPFLAGS="$CPPFLAGS $ICU_CFLAGS"
RAPTOR_LDFLAGS="$RAPTOR_LDFLAGS $ICU_LIBS"
AC_LIBOBJ(raptor_nfc_icu)
- nfc_library="ICU $ICU_VERSION"
+ nfc_library="ICU UC $ICU_UC_VERSION"
fi
AC_MSG_RESULT($nfc_library)
diff --git a/src/raptor_nfc_icu.c b/src/raptor_nfc_icu.c
index 50433808..9d17982a 100644
--- a/src/raptor_nfc_icu.c
+++ b/src/raptor_nfc_icu.c
@@ -40,7 +40,12 @@
#include "raptor2.h"
#include "raptor_internal.h"
+#if ICU_UC_MAJOR_VERSION >= 56
+#include <unicode/unorm2.h>
+#else
#include <unicode/unorm.h>
+#endif
+
/**
* raptor_nfc_icu_check:
@@ -58,9 +63,34 @@
int
raptor_nfc_icu_check(const unsigned char* string, size_t len, int *error)
{
+ /* unorm_quickCheck was deprecated in ICU UC V56 */
+
+#if ICU_UC_MAJOR_VERSION >= 56
+ /* norm2 is be a singleton - do not attempt to free it */
+ const UNormalizer2 *norm2;
+ UErrorCode error_code = U_ZERO_ERROR;
+ UNormalizationCheckResult res;
+
+ norm2 = unorm2_getNFCInstance(&error_code);
+ if(!U_SUCCESS(error_code)) {
+ if(error)
+ *error = 1;
+ return 0;
+ }
+
+ res = unorm2_quickCheck(norm2,(const UChar *)string, (int32_t)len,
+ &error_code);
+ if(!U_SUCCESS(error_code)) {
+ if(error)
+ *error = 1;
+ return 0;
+ }
+
+ return (res == UNORM_YES);
+#else
UNormalizationCheckResult res;
UErrorCode error_code = U_ZERO_ERROR;
-
+
res = unorm_quickCheck((const UChar *)string, (int32_t)len,
UNORM_NFC, &error_code);
if(!U_SUCCESS(error_code)) {
@@ -70,4 +100,5 @@ raptor_nfc_icu_check(const unsigned char* string, size_t len, int *error)
}
return (res == UNORM_YES);
+#endif
}