diff options
author | Dan Williams <dan@ioncontrol.co> | 2025-05-06 08:54:29 -0500 |
---|---|---|
committer | Dan Williams <dan@ioncontrol.co> | 2025-05-30 08:02:47 -0500 |
commit | 56fe8e7d314c637d6df45f693e2377b18685a405 (patch) | |
tree | b5b6a541241ae7bf77f33bebf3c12100e67c4c3b /src/mm-modem-helpers.c | |
parent | 957a141e57e622a9d7eeac160d67be5b0b4cdf7c (diff) |
modem-helpers: add utility function to split DTMF runs
Split into groups of non-pause characters and single pause characters
by themselves and return as an array of strings.
Signed-off-by: Dan Williams <dan@ioncontrol.co>
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r-- | src/mm-modem-helpers.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 0e258e61..5cbf0836 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -5887,3 +5887,37 @@ mm_dtmf_duration_normalize (guint duration_ms) return CLAMP (duration_ms, 100, 1000); } + +GPtrArray * +mm_dtmf_split (const gchar *dtmf) +{ + GPtrArray *array; + const gchar *p = dtmf; + GString *cur = NULL; + + array = g_ptr_array_new (); + + while (*p) { + if (*p == MM_CALL_DTMF_PAUSE_CHAR) { + if (cur) { + g_ptr_array_add (array, g_string_free (cur, FALSE)); + cur = NULL; + } + g_ptr_array_add (array, g_strdup (",")); + } else { + if (!cur) + cur = g_string_new (NULL); + g_string_append_c (cur, *p); + } + p++; + } + if (cur) + g_ptr_array_add (array, g_string_free (cur, FALSE)); + + if (array->len == 0) { + g_ptr_array_free (array, TRUE); + return NULL; + } + + return array; +} |