diff options
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r-- | src/mm-modem-helpers.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 3b2e9e1a..9e875a62 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1820,3 +1820,40 @@ mm_count_bits_set (gulong number) number &= number - 1; return c; } + +GStrv +mm_3gpp_parse_cnum_response (const gchar *reply, + GError **error) +{ + GArray *array = NULL; + GRegex *r; + GMatchInfo *match_info; + + /* Empty strings also return NULL list */ + if (!reply || !reply[0]) + return NULL; + + r = g_regex_new ("\\+CNUM:\\s*\"?\\S*\"?,\"(\\S+)\",\\d", G_REGEX_UNGREEDY, 0, NULL); + g_assert (r != NULL); + + g_regex_match (r, reply, 0, &match_info); + while (g_match_info_matches (match_info)) { + gchar *number; + + number = g_match_info_fetch (match_info, 1); + + if (number && number[0]) { + if (!array) + array = g_array_new (TRUE, TRUE, sizeof (gchar *)); + g_array_append_val (array, number); + } else + g_free (number); + + g_match_info_next (match_info, NULL); + } + + g_match_info_free (match_info); + g_regex_unref (r); + + return (array ? (GStrv) g_array_free (array, FALSE) : NULL); +} |