Use NOCase String As G

xiaoxiao2021-03-06  100

/ * ghashtableDemo.c - ghashtable demo * /

#include

#include

Void Print_ENTRY (GPOINTER KEY, GPOINTER DATA, GPOINTER USER_DATA) {/ * user_data not used * / g_print ("key:% -10s value:% -10s / n", (gchar *) key, (gchar *) DATA); }

Guint g_str_case_hash (gchar * Upkey = g_ascii_strdown (key, strlen (key)); guint hash = g_str_hash (Upkey); g_free (UpKey); Return hash;}

GBOOLEAN G_STR_CASE_EQUAL (GConstPointer A, gconstpointer b) {if (! g_ascii_strcasecmp (a, b)) Return True; ELSE RETURN G_STR_EQUAL (A, B);}

INT Main (int Argc, char * argv []) {ghashtable * hash1; hash1 = g_haash_table_new (g_str_case_hash, g_str_case_equal);

/ * Insert a bunch of entries * / g_hash_table_replace (hash1, g_strdup ( "foo"), g_strdup ( "bar")); g_hash_table_replace (hash1, g_strdup ( "FoO"), g_strdup ( "BAR")); g_hash_table_replace (hash1 , g_strdup ("more"), g_strdup ("junk");

/ * Print the contents * / g_print ("Hash Table Entries: / N"); g_hash_table_foreach (hash1, print_entry, null);

Return 0;}

/ * * Gcc -ansi -wall `pkg-config glib-2.0 --cflags` -o test test.c` pkg-config glib-2.0 --libs` * /

转载请注明原文地址:https://www.9cbs.com/read-123790.html

New Post(0)