diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2016-07-16 14:05:30 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2016-07-16 14:05:30 +0200 |
commit | 13bc9603a8802bbd0b6ea03f0ad07fbe0a3192cc (patch) | |
tree | d8aed4699ad7994d707a6419fba7826d63de15c4 /src | |
parent | 03bcbda3c2a8624cc0cfed3c889e270cf008bb19 (diff) | |
download | tracker-13bc9603a8802bbd0b6ea03f0ad07fbe0a3192cc.tar.gz |
libtracker-extract: Add tracker_guarantee_resource_utf8_string()
This is a wrapper to tracker_resource_set_string(), which additionally
validates the string to be UTF-8, and inserts only as much text as
could be validated.
Can be thought of as an internal replacement to
tracker_sparql_builder_object_unvalidated(), the fact that we deal with
non utf-8 data sources is an implementation detail to extractors, so
it doesn't make as much sense to make this a public function in the
shiny new TrackerResource API.
Diffstat (limited to 'src')
-rw-r--r-- | src/libtracker-extract/tracker-guarantee.c | 22 | ||||
-rw-r--r-- | src/libtracker-extract/tracker-guarantee.h | 3 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/libtracker-extract/tracker-guarantee.c b/src/libtracker-extract/tracker-guarantee.c index 9b8460a08..5c595c9ad 100644 --- a/src/libtracker-extract/tracker-guarantee.c +++ b/src/libtracker-extract/tracker-guarantee.c @@ -348,3 +348,25 @@ tracker_guarantee_resource_date_from_file_mtime (TrackerResource *resource, return success; } + +gboolean +tracker_guarantee_resource_utf8_string (TrackerResource *resource, + const gchar *key, + const gchar *value) +{ + const gchar *end; + gchar *str; + + if (!g_utf8_validate (value, -1, &end)) { + if (end == value) + return FALSE; + + str = g_strndup (value, end - value); + tracker_resource_set_string (resource, key, str); + g_free (str); + } else { + tracker_resource_set_string (resource, key, value); + } + + return TRUE; +} diff --git a/src/libtracker-extract/tracker-guarantee.h b/src/libtracker-extract/tracker-guarantee.h index 9b58a634a..cdb28c24a 100644 --- a/src/libtracker-extract/tracker-guarantee.h +++ b/src/libtracker-extract/tracker-guarantee.h @@ -49,6 +49,9 @@ gboolean tracker_guarantee_resource_date_from_file_mtime (TrackerResource *reso const gchar *key, const gchar *current_value, const gchar *uri); +gboolean tracker_guarantee_resource_utf8_string (TrackerResource *resource, + const gchar *key, + const gchar *value); G_END_DECLS |