[tepl] Metadata: common function to check if a value is valid



commit 20e6db8e27005660eb8bf22179bd8646ae0a231a
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Apr 19 01:28:21 2020 +0200

    Metadata: common function to check if a value is valid
    
    That way if the requirements change, there is only one place to change.

 tepl/tepl-metadata-attic.c |  2 +-
 tepl/tepl-metadata.c       | 13 ++++++++++++-
 tepl/tepl-metadata.h       |  3 +++
 3 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/tepl/tepl-metadata-attic.c b/tepl/tepl-metadata-attic.c
index 83000b5..ae3e38c 100644
--- a/tepl/tepl-metadata-attic.c
+++ b/tepl/tepl-metadata-attic.c
@@ -120,7 +120,7 @@ _tepl_metadata_attic_insert_entry (TeplMetadataAttic *metadata,
 {
        g_return_if_fail (TEPL_IS_METADATA_ATTIC (metadata));
        g_return_if_fail (_tepl_metadata_key_is_valid (key));
-       g_return_if_fail (g_utf8_validate (value, -1, NULL));
+       g_return_if_fail (_tepl_metadata_value_is_valid (value));
 
        g_hash_table_replace (metadata->priv->hash_table,
                              g_strdup (key),
diff --git a/tepl/tepl-metadata.c b/tepl/tepl-metadata.c
index 9dfe77e..28429bd 100644
--- a/tepl/tepl-metadata.c
+++ b/tepl/tepl-metadata.c
@@ -150,7 +150,7 @@ tepl_metadata_set (TeplMetadata *metadata,
 {
        g_return_if_fail (TEPL_IS_METADATA (metadata));
        g_return_if_fail (_tepl_metadata_key_is_valid (key));
-       g_return_if_fail (value == NULL || g_utf8_validate (value, -1, NULL));
+       g_return_if_fail (value == NULL || _tepl_metadata_value_is_valid (value));
 
        g_hash_table_replace (metadata->priv->hash_table,
                              g_strdup (key),
@@ -210,3 +210,14 @@ _tepl_metadata_key_is_valid (const gchar *key)
 
        return TRUE;
 }
+
+gboolean
+_tepl_metadata_value_is_valid (const gchar *value)
+{
+       if (value == NULL)
+       {
+               return FALSE;
+       }
+
+       return g_utf8_validate (value, -1, NULL);
+}
diff --git a/tepl/tepl-metadata.h b/tepl/tepl-metadata.h
index 12ef2f4..f80ee02 100644
--- a/tepl/tepl-metadata.h
+++ b/tepl/tepl-metadata.h
@@ -72,6 +72,9 @@ void          _tepl_metadata_foreach          (TeplMetadata *metadata,
 G_GNUC_INTERNAL
 gboolean       _tepl_metadata_key_is_valid     (const gchar *key);
 
+G_GNUC_INTERNAL
+gboolean       _tepl_metadata_value_is_valid   (const gchar *value);
+
 G_END_DECLS
 
 #endif /* TEPL_METADATA_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]