Exemplo n.º 1
0
static void
quickfill_insert_recursive (QuickFill *qf, const char *text, int len,
                            const char *next_char, QuickFillSort sort)
{
    guint key;
    char *old_text;
    QuickFill *match_qf;
    gunichar key_char_uc;

    if (qf == NULL)
        return;

    if ((text == NULL) || (*next_char == '\0'))
        return;


    key_char_uc = g_utf8_get_char (next_char);
    key = g_unichar_toupper (key_char_uc);

    match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
    if (match_qf == NULL)
    {
        match_qf = gnc_quickfill_new ();
        g_hash_table_insert (qf->matches, GUINT_TO_POINTER (key), match_qf);
    }

    old_text = match_qf->text;

    switch (sort)
    {
    case QUICKFILL_ALPHA:
        if (old_text && (g_utf8_collate (text, old_text) >= 0))
            break;
        /* fall through */

    case QUICKFILL_LIFO:
    default:
        /* If there's no string there already, just put the new one in. */
        if (old_text == NULL)
        {
            match_qf->text = g_strdup(text);
            match_qf->len = len;
            break;
        }

        /* Leave prefixes in place */
        if ((len > match_qf->len) &&
                (strncmp(text, old_text, strlen(old_text)) == 0))
            break;

        g_free(old_text);
        match_qf->text = g_strdup(text);
        match_qf->len = len;
        break;
    }

    quickfill_insert_recursive (match_qf, text, len, g_utf8_next_char (next_char), sort);
}
Exemplo n.º 2
0
void
gnc_quickfill_insert (QuickFill *qf, const char *text, QuickFillSort sort)
{
    gchar *normalized_str;

    if (NULL == qf) return;
    if (NULL == text) return;


    normalized_str = g_utf8_normalize (text, -1, G_NORMALIZE_NFC);
    quickfill_insert_recursive (qf, normalized_str, 0, sort);
    g_free (normalized_str);
}
Exemplo n.º 3
0
static void
quickfill_insert_recursive (QuickFill *qf, const char *text, int depth,
                            QuickFillSort sort)
{
    guint key;
    char *old_text;
    QuickFill *match_qf;
    int len;
    char *key_char;
    gunichar key_char_uc;

    if (qf == NULL)
        return;

    if ((text == NULL) || (g_utf8_strlen (text, -1) <= depth))
        return;

    key_char = g_utf8_offset_to_pointer (text, depth);

    key_char_uc = g_utf8_get_char (key_char);
    key = g_unichar_toupper (key_char_uc);

    match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
    if (match_qf == NULL)
    {
        match_qf = gnc_quickfill_new ();
        g_hash_table_insert (qf->matches, GUINT_TO_POINTER (key), match_qf);
    }

    old_text = match_qf->text;

    switch (sort)
    {
    case QUICKFILL_ALPHA:
        if (old_text && (g_utf8_collate (text, old_text) >= 0))
            break;
        /* fall through */

    case QUICKFILL_LIFO:
    default:
        len = g_utf8_strlen (text, -1);

        /* If there's no string there already, just put the new one in. */
        if (old_text == NULL)
        {
            match_qf->text = CACHE_INSERT((gpointer) text);
            match_qf->len = len;
            break;
        }

        /* Leave prefixes in place */
        if ((len > match_qf->len) &&
                (strncmp(text, old_text, strlen(old_text)) == 0))
            break;

        CACHE_REMOVE(old_text);
        match_qf->text = CACHE_INSERT((gpointer) text);
        match_qf->len = len;
        break;
    }

    quickfill_insert_recursive (match_qf, text, ++depth, sort);
}