From 1c7304eb718a76dc679b1c08d3e5f0a5cf2d7a2d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 06:22:34 +0100 Subject: [PATCH] libmm-glib,helpers: allow reading hex strings from match info --- libmm-glib/mm-common-helpers.c | 25 +++++++++++++++++++++++++ libmm-glib/mm-common-helpers.h | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index cdb9115c..8e0fc601 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1491,6 +1491,31 @@ mm_get_u64_from_match_info (GMatchInfo *match_info, return (s ? mm_get_u64_from_str (s, out) : FALSE); } +gboolean +mm_get_uint_from_hex_match_info (GMatchInfo *match_info, + guint32 match_index, + guint *out) +{ + guint64 num; + + if (!mm_get_u64_from_hex_match_info (match_info, match_index, &num) || num > G_MAXUINT) + return FALSE; + + *out = (guint)num; + return TRUE; +} + +gboolean +mm_get_u64_from_hex_match_info (GMatchInfo *match_info, + guint32 match_index, + guint64 *out) +{ + g_autofree gchar *s = NULL; + + s = mm_get_string_unquoted_from_match_info (match_info, match_index); + return (s ? mm_get_u64_from_hex_str (s, out) : FALSE); +} + gboolean mm_get_double_from_str (const gchar *str, gdouble *out) diff --git a/libmm-glib/mm-common-helpers.h b/libmm-glib/mm-common-helpers.h index be9f2bb8..65d0e70a 100644 --- a/libmm-glib/mm-common-helpers.h +++ b/libmm-glib/mm-common-helpers.h @@ -164,6 +164,12 @@ gboolean mm_get_uint_from_match_info (GMatchInfo *match_info, gboolean mm_get_u64_from_match_info (GMatchInfo *match_info, guint32 match_index, guint64 *out); +gboolean mm_get_uint_from_hex_match_info (GMatchInfo *match_info, + guint32 match_index, + guint *out); +gboolean mm_get_u64_from_hex_match_info (GMatchInfo *match_info, + guint32 match_index, + guint64 *out); gboolean mm_get_double_from_str (const gchar *str, gdouble *out); gboolean mm_get_double_from_match_info (GMatchInfo *match_info,