From 9db4948e44f10878fbea15a35cfe82fb853177ec Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Wed, 2 May 2007 14:01:36 +0000 Subject: [PATCH] tweaking, still no good results with danish sorting --- src/icu_I18N.c | 27 +++++---------------------- src/icu_I18N.h | 5 ++--- src/test_icu_I18N.c | 33 ++++++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/icu_I18N.c b/src/icu_I18N.c index 25951fe..c0a7407 100644 --- a/src/icu_I18N.c +++ b/src/icu_I18N.c @@ -1,4 +1,4 @@ -/* $Id: icu_I18N.c,v 1.3 2007-05-01 13:16:09 marc Exp $ +/* $Id: icu_I18N.c,v 1.4 2007-05-02 14:01:36 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -81,9 +81,10 @@ int32_t icu_utf16_casemap(UChar *dest16, int32_t dest16_cap, int icu_check_status (UErrorCode status) { - if(U_FAILURE(status)) + //if(U_FAILURE(status)) + if(!U_SUCCESS(status)) yaz_log(YLOG_WARN, - "ICU Error: %d %s\n", status, u_errorName(status)); + "ICU: %d %s\n", status, u_errorName(status)); return status; } @@ -211,7 +212,6 @@ char * icu_casemap(NMEM nmem, char *buf, size_t buf_cap, struct icu_termmap * icu_termmap_create(NMEM nmem) { struct icu_termmap *itmp = nmem_malloc(nmem, sizeof(*itmp)); - itmp->sort_len = 0; itmp->sort_key = 0; itmp->norm_term = 0; itmp->disp_term = 0; @@ -222,25 +222,8 @@ int icu_termmap_cmp(const void *vp1, const void *vp2) { struct icu_termmap *itmp1 = *(struct icu_termmap **) vp1; struct icu_termmap *itmp2 = *(struct icu_termmap **) vp2; - int cmp = 0; -#if 0 - size_t len = itmp1->sort_len; - // minimum sortkey length - if (itmp2->sort_len < len) - len = itmp2->sort_len; - - cmp = strncmp(itmp1->sort_key, itmp2->sort_key, len); - - if (cmp == 0 && (itmp1->sort_len < itmp2->sort_len)) - cmp = -1; - - if (cmp == 0 && (itmp1->sort_len > itmp2->sort_len)) - cmp = 1; -#else - cmp = strcmp(itmp1->sort_key, itmp2->sort_key); -#endif - return cmp; + return strcmp(itmp1->sort_key, itmp2->sort_key); } diff --git a/src/icu_I18N.h b/src/icu_I18N.h index 299058d..6dc7096 100644 --- a/src/icu_I18N.h +++ b/src/icu_I18N.h @@ -1,4 +1,4 @@ -/* $Id: icu_I18N.h,v 1.3 2007-05-01 13:16:09 marc Exp $ +/* $Id: icu_I18N.h,v 1.4 2007-05-02 14:01:36 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -42,8 +42,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA struct icu_termmap { - size_t sort_len; // needed, because - char * sort_key; // no guarantee on '\0' termination ??? + char * sort_key; // standard C string '\0' terminated char * norm_term; // standard C utf-8 string char * disp_term; // standard C utf-8 string }; diff --git a/src/test_icu_I18N.c b/src/test_icu_I18N.c index 3a4c253..62b5255 100644 --- a/src/test_icu_I18N.c +++ b/src/test_icu_I18N.c @@ -1,4 +1,4 @@ -/* $Id: test_icu_I18N.c,v 1.6 2007-05-01 13:27:32 marc Exp $ +/* $Id: test_icu_I18N.c,v 1.7 2007-05-02 14:01:36 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -219,8 +219,9 @@ int test_icu_sortmap(const char * locale, size_t list_len, //dest8_list[i]->sort_key = nmem_strdup(nmem, src8_list[i]); //dest8_list[i]->sort_len = strlen(src8_list[i]); dest8_list[i]->sort_key - = icu_sortmap(nmem, buf, buf_cap, &(dest8_list[i]->sort_len), - src8_list[i], locale); + = icu_sortmap(nmem, buf, buf_cap, 0, src8_list[i], locale); + // = icu_sortmap(nmem, buf, buf_cap, &(dest8_list[i]->sort_len), + // src8_list[i], locale); } // do the sorting @@ -234,12 +235,26 @@ int test_icu_sortmap(const char * locale, size_t list_len, } } - if (!sucess) - for (i = 0; i < list_len; i++){ - printf("icu_sortmap '%s': '%s' '%s'\n", locale, - dest8_list[i]->disp_term, check8_list[i]); - } - + if (1 || !sucess){ + printf("\n"); + printf("Input '%s':", locale); + for (i = 0; i < list_len; i++) + printf(" '%s'", src8_list[i]); + printf("\n"); + printf("ICU sort '%s':", locale); + for (i = 0; i < list_len; i++) + printf(" '%s'", dest8_list[i]->disp_term); + if (sucess) + printf(" OK"); + else + printf(" ERROR ??"); + printf("\n"); + printf("Expected '%s':", locale); + for (i = 0; i < list_len; i++) + printf(" '%s'", check8_list[i]); + printf("\n"); + } + nmem_destroy(nmem); return sucess; -- 1.7.10.4