From ecca39963661489bc5a13b46bf8e181e20534d8d Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Tue, 31 Dec 2019 13:34:36 +0100 Subject: [PATCH] New function Signed-off-by: Michael Rasmussen --- src/vcard-parser.c | 80 +++++++++++++++++++++++----------------------- src/vcard-parser.h | 1 + src/vcard.c | 2 -- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/vcard-parser.c b/src/vcard-parser.c index e35dba8..a62d8d3 100644 --- a/src/vcard-parser.c +++ b/src/vcard-parser.c @@ -175,46 +175,6 @@ static gchar** vcard_text_normalize(const gchar** text) { return new; } -Property vcard_max_property(VCardVersion version) { - Property p = VCARD_PROPERTIES; - - if (version == VCARD_VERSION_2_1) { - p = TZ; - } else if (version == VCARD_VERSION_3_0) { - p = IMPP; - } else if (version == VCARD_VERSION_4_0) { - p = VCARD_PROPERTIES - 1; - } - - return p; -} - -void destroy_hash_table(GHashTable* ht) { - GHashTableIter iter; - gpointer key, value; - - g_hash_table_iter_init (&iter, ht); - while (g_hash_table_iter_next(&iter, &key, &value)) { - if (value) - g_slist_free_full((GSList *) value, vcard_property_free); - } - - g_hash_table_destroy(ht); -} - -static void init_g_hash_table(GHashTable** ht, VCardVersion version) { - if (!ht) return; - - Property property = vcard_max_property(version); - if (property < VCARD_PROPERTIES) { - *ht = g_hash_table_new_full( - g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL); - for (Property i = N; i <= property; i++) { - g_hash_table_insert(*ht, g_strdup(Properties[i]), NULL); - } - } -} - static VCardParserResponse vcard_parse(gchar** text, VCardVersion version, GHashTable** vcard) { VCardParserResponse r = VCARD_PARSER_ERROR; guint l = g_strv_length(text); @@ -264,6 +224,46 @@ static VCardParserResponse vcard_parse(gchar** text, VCardVersion version, GHash return r; } +Property vcard_max_property(VCardVersion version) { + Property p = VCARD_PROPERTIES; + + if (version == VCARD_VERSION_2_1) { + p = TZ; + } else if (version == VCARD_VERSION_3_0) { + p = IMPP; + } else if (version == VCARD_VERSION_4_0) { + p = VCARD_PROPERTIES - 1; + } + + return p; +} + +void destroy_hash_table(GHashTable* ht) { + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init (&iter, ht); + while (g_hash_table_iter_next(&iter, &key, &value)) { + if (value) + g_slist_free_full((GSList *) value, vcard_property_free); + } + + g_hash_table_destroy(ht); +} + +void init_g_hash_table(GHashTable** ht, VCardVersion version) { + if (!ht) return; + + Property property = vcard_max_property(version); + if (property < VCARD_PROPERTIES) { + *ht = g_hash_table_new_full( + g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL); + for (Property i = N; i <= property; i++) { + g_hash_table_insert(*ht, g_strdup(Properties[i]), NULL); + } + } +} + VCardVersion str_2_vcard_version(const gchar* version) { VCardVersion vv = VCARD_VERSION_DETECT; diff --git a/src/vcard-parser.h b/src/vcard-parser.h index 0eb4670..d812ab8 100644 --- a/src/vcard-parser.h +++ b/src/vcard-parser.h @@ -111,6 +111,7 @@ VCardVersion str_2_vcard_version(const gchar* version); gchar* vcard_version_2_str(VCardVersion version); Property vcard_max_property(VCardVersion version); VCardParserResponse vcard_parse_text(const gchar* text, VCardVersion* version, GHashTable** vcard); +void init_g_hash_table(GHashTable** ht, VCardVersion version); void destroy_hash_table(GHashTable* ht); G_END_DECLS diff --git a/src/vcard.c b/src/vcard.c index e9881f9..cba62ad 100644 --- a/src/vcard.c +++ b/src/vcard.c @@ -135,14 +135,12 @@ void VCard_list_free(GSList* list) { g_slist_free(list); } -/* VCard* VCard_new(VCardVersion version) { VCard* vc = g_new0(VCard, 1); vc->version = version; return vc; } -*/ GSList* VCard_new_from_text(const gchar* text, VCardVersion version, gboolean skip_broken) { GSList* list = NULL; -- 2.39.2