[tracker/wip/carlosg/compiler-warnings: 10/10] libtracker-common, data: Port libicu paths to unorm2_normalize



commit 53759e7ccec16b659bc55120d4eb18080208efad
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Oct 1 01:40:29 2018 +0200

    libtracker-common,data: Port libicu paths to unorm2_normalize
    
    The old unorm_normalize() function has been deprecated. This replacement
    function is available on ICU >= 4.4, so we should be fine dependency-wise.

 src/libtracker-common/tracker-parser-libicu.c     | 19 +++++++-----
 src/libtracker-common/tracker-parser.h            |  2 +-
 src/libtracker-data/tracker-db-interface-sqlite.c | 36 ++++++++++++++---------
 3 files changed, 35 insertions(+), 22 deletions(-)
---
diff --git a/src/libtracker-common/tracker-parser-libicu.c b/src/libtracker-common/tracker-parser-libicu.c
index d6410d346..cbd260a2c 100644
--- a/src/libtracker-common/tracker-parser-libicu.c
+++ b/src/libtracker-common/tracker-parser-libicu.c
@@ -272,6 +272,7 @@ process_word_uchar (TrackerParser         *parser,
 
        if (type != TRACKER_PARSER_WORD_TYPE_ASCII) {
                UChar casefolded_buffer [WORD_BUFFER_LENGTH];
+               const UNormalizer2 *normalizer;
 
                /* Casefold... */
                new_word_length = u_strFoldCase (casefolded_buffer,
@@ -294,13 +295,17 @@ process_word_uchar (TrackerParser         *parser,
                                            new_word_length * sizeof (UChar));
 
                /* NFKD normalization... */
-               new_word_length = unorm_normalize (casefolded_buffer,
-                                                  new_word_length,
-                                                  UNORM_NFKD,
-                                                  0,
-                                                  normalized_buffer,
-                                                  WORD_BUFFER_LENGTH,
-                                                  &error);
+               normalizer = unorm2_getNFKDInstance (&error);
+
+               if (U_SUCCESS (error)) {
+                       new_word_length = unorm2_normalize (normalizer,
+                                                           casefolded_buffer,
+                                                           new_word_length,
+                                                           normalized_buffer,
+                                                           WORD_BUFFER_LENGTH,
+                                                           &error);
+               }
+
                if (U_FAILURE (error)) {
                        g_warning ("Error normalizing: '%s'",
                                   u_errorName (error));
diff --git a/src/libtracker-common/tracker-parser.h b/src/libtracker-common/tracker-parser.h
index 90c8facc3..28b9e1cb1 100644
--- a/src/libtracker-common/tracker-parser.h
+++ b/src/libtracker-common/tracker-parser.h
@@ -30,7 +30,7 @@
  * at runtime, the former must be rebuilt for those to match perfectly
  * to avoid returning meaningless results on FTS searches.
  */
-#define TRACKER_PARSER_VERSION 1
+#define TRACKER_PARSER_VERSION 2
 
 G_BEGIN_DECLS
 
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c 
b/src/libtracker-data/tracker-db-interface-sqlite.c
index e1c249409..dbecce9e5 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -47,6 +47,7 @@
 #include <unicode/uregex.h>
 #include <unicode/ustring.h>
 #include <unicode/ucol.h>
+#include <unicode/unorm2.h>
 #endif
 
 #include "tracker-collation.h"
@@ -1025,7 +1026,7 @@ function_sparql_case_fold (sqlite3_context *context,
 static gunichar2 *
 normalize_string (const gunichar2    *string,
                   gsize               string_len, /* In gunichar2s */
-                  UNormalizationMode  mode,
+                  const UNormalizer2 *normalizer,
                   gsize              *len_out,    /* In gunichar2s */
                   UErrorCode         *status)
 {
@@ -1035,14 +1036,14 @@ normalize_string (const gunichar2    *string,
        nOutput = (string_len * 2) + 1;
        zOutput = g_new0 (gunichar2, nOutput);
 
-       nOutput = unorm_normalize (string, string_len, mode, 0, zOutput, nOutput, status);
+       nOutput = unorm2_normalize (normalizer, string, string_len, zOutput, nOutput, status);
 
        if (*status == U_BUFFER_OVERFLOW_ERROR) {
                /* Try again after allocating enough space for the normalization */
                *status = U_ZERO_ERROR;
                zOutput = g_renew (gunichar2, zOutput, nOutput);
                memset (zOutput, 0, nOutput * sizeof (gunichar2));
-               nOutput = unorm_normalize (string, string_len, mode, 0, zOutput, nOutput, status);
+               nOutput = unorm2_normalize (normalizer, string, string_len, zOutput, nOutput, status);
        }
 
        if (!U_SUCCESS (*status)) {
@@ -1063,10 +1064,10 @@ function_sparql_normalize (sqlite3_context *context,
 {
        const gchar *nfstr;
        const uint16_t *zInput;
-       uint16_t *zOutput;
+       uint16_t *zOutput = NULL;
        int nInput;
        gsize nOutput;
-       UNormalizationMode nf;
+       const UNormalizer2 *normalizer;
        UErrorCode status = U_ZERO_ERROR;
 
        if (argc != 2) {
@@ -1082,20 +1083,22 @@ function_sparql_normalize (sqlite3_context *context,
 
        nfstr = (gchar *)sqlite3_value_text (argv[1]);
        if (g_ascii_strcasecmp (nfstr, "nfc") == 0)
-               nf = UNORM_NFC;
+               normalizer = unorm2_getNFCInstance (&status);
        else if (g_ascii_strcasecmp (nfstr, "nfd") == 0)
-               nf = UNORM_NFD;
+               normalizer = unorm2_getNFDInstance (&status);
        else if (g_ascii_strcasecmp (nfstr, "nfkc") == 0)
-               nf = UNORM_NFKC;
+               normalizer = unorm2_getNFKCInstance (&status);
        else if (g_ascii_strcasecmp (nfstr, "nfkd") == 0)
-               nf = UNORM_NFKD;
+               normalizer = unorm2_getNFKDInstance (&status);
        else {
                sqlite3_result_error (context, "Invalid normalization specified", -1);
                return;
        }
 
-       nInput = sqlite3_value_bytes16 (argv[0]);
-       zOutput = normalize_string (zInput, nInput / 2, nf, &nOutput, &status);
+       if (U_SUCCESS (status)) {
+               nInput = sqlite3_value_bytes16 (argv[0]);
+               zOutput = normalize_string (zInput, nInput / 2, normalizer, &nOutput, &status);
+       }
 
        if (!U_SUCCESS (status)) {
                char zBuf[128];
@@ -1115,9 +1118,10 @@ function_sparql_unaccent (sqlite3_context *context,
                           sqlite3_value   *argv[])
 {
        const uint16_t *zInput;
-       uint16_t *zOutput;
+       uint16_t *zOutput = NULL;
        int nInput;
        gsize nOutput;
+       const UNormalizer2 *normalizer;
        UErrorCode status = U_ZERO_ERROR;
 
        g_assert (argc == 1);
@@ -1128,8 +1132,12 @@ function_sparql_unaccent (sqlite3_context *context,
                return;
        }
 
-       nInput = sqlite3_value_bytes16 (argv[0]);
-       zOutput = normalize_string (zInput, nInput / 2, UNORM_NFKD, &nOutput, &status);
+       normalizer = unorm2_getNFKDInstance (&status);
+
+       if (U_SUCCESS (status)) {
+               nInput = sqlite3_value_bytes16 (argv[0]);
+               zOutput = normalize_string (zInput, nInput / 2, normalizer, &nOutput, &status);
+       }
 
        if (!U_SUCCESS (status)) {
                char zBuf[128];


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]