Ejemplo n.º 1
0
const char *icu_chain_token_sortkey(struct icu_chain *chain)
{
    if (chain->iter)
        return icu_iter_get_sortkey(chain->iter);
    return 0;
}
Ejemplo n.º 2
0
static const char *pp2_get_sort_icu(pp2_charset_token_t prt)
{
    return icu_iter_get_sortkey(prt->iter);
}
Ejemplo n.º 3
0
static int test_iter(struct icu_chain *chain, const char *input,
                     const char *expected)
{
    yaz_icu_iter_t iter = icu_iter_create(chain);
    WRBUF result, second, sort_result;
    int success = 1;

    if (!iter)
    {
        yaz_log(YLOG_WARN, "test_iter: input=%s !iter", input);
        return 0;
    }

    if (icu_iter_next(iter))
    {
        yaz_log(YLOG_WARN, "test_iter: expecting 0 before icu_iter_first");
        return 0;
    }

    sort_result = wrbuf_alloc();
    result = wrbuf_alloc();
    icu_iter_first(iter, input);
    while (icu_iter_next(iter))
    {
        const char *sort_str = icu_iter_get_sortkey(iter);
        if (sort_str)
        {
            wrbuf_puts(sort_result, "[");
            wrbuf_puts_escaped(sort_result, sort_str);
            wrbuf_puts(sort_result, "]");
        }
        else
        {
            wrbuf_puts(sort_result, "[NULL]");
        }
        wrbuf_puts(result, "[");
        wrbuf_puts(result, icu_iter_get_norm(iter));
        wrbuf_puts(result, "]");
    }
    yaz_log(YLOG_LOG, "sortkey=%s", wrbuf_cstr(sort_result));
    second = wrbuf_alloc();
    icu_iter_first(iter, input);
    while (icu_iter_next(iter))
    {
        wrbuf_puts(second, "[");
        wrbuf_puts(second, icu_iter_get_norm(iter));
        wrbuf_puts(second, "]");
    }

    icu_iter_destroy(iter);

    if (strcmp(expected, wrbuf_cstr(result)))
    {
        yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s",
                input, expected, wrbuf_cstr(result));
        success = 0;
    }

    if (strcmp(expected, wrbuf_cstr(second)))
    {
        yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s (2nd)",
                input, expected, wrbuf_cstr(second));
        success = 0;
    }

    wrbuf_destroy(result);
    wrbuf_destroy(second);
    wrbuf_destroy(sort_result);
    return success;
}