X-Git-Url: http://git.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Ficu_I18N.c;h=25951fe98a2e83d7971a32a19b56e6f1768a14e8;hb=b25ec6b732e94d0f8ee3582328ca2b1b34a4cc4a;hp=704416056345e3bbe6294713cf7ec7fc58bbb1ce;hpb=273b54f5a836e08765596af85ad74654828a21b8;p=pazpar2-moved-to-github.git diff --git a/src/icu_I18N.c b/src/icu_I18N.c index 7044160..25951fe 100644 --- a/src/icu_I18N.c +++ b/src/icu_I18N.c @@ -1,4 +1,4 @@ -/* $Id: icu_I18N.c,v 1.2 2007-05-01 08:17:05 marc Exp $ +/* $Id: icu_I18N.c,v 1.3 2007-05-01 13:16:09 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -42,7 +42,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA //#include //#include /* Basic ICU data types */ -//#include +#include //#include /* C Converter API */ //#include //#include @@ -77,7 +77,7 @@ int32_t icu_utf16_casemap(UChar *dest16, int32_t dest16_cap, const char *locale, char action); -// source code +// source code of all functions int icu_check_status (UErrorCode status) { @@ -208,6 +208,93 @@ 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; + return itmp; +}; + +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; +} + + + +char * icu_sortmap(NMEM nmem, char *buf, size_t buf_cap, + size_t *dest8_len, const char *src8, + const char *locale) +{ + size_t src8_len = strlen(src8); + int32_t buf_len = 0; + char * dest8 = 0; + + if (dest8_len) + *dest8_len = 0; + + if (!buf || !(buf_cap > 0) || !src8_len) + return 0; + + // converting buf to utf16 + buf = (char *)icu_utf16_from_utf8n((UChar *) buf, + (int32_t) buf_cap, &buf_len, + src8, src8_len); + + // sort mapping + //buf_len = (size_t) icu_utf16_casemap((UChar *)buf, (int32_t) buf_cap, + // (const UChar *)buf, (int32_t) buf_len, + // locale, action); + + + { + UErrorCode status = U_ZERO_ERROR; + + UCollator * coll = ucol_open (locale, &status); + if (U_ZERO_ERROR != icu_check_status(status)) + buf_len = 0; + + ucol_getSortKey(coll, (const UChar *) buf, (int32_t) buf_len, + (uint8_t *) buf, (int32_t) buf_cap); + + ucol_close(coll); + } + + + // copying out to nmem + buf[buf_len] = '\0'; + + if(dest8_len) + *dest8_len = buf_len; + + dest8 = nmem_strdup(nmem, buf); + return dest8; +} + + #endif // HAVE_ICU