aboutsummaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksandermj@chromium.org>2024-03-07 14:09:28 +0000
committerAleksander Morgado <aleksandermj@chromium.org>2024-03-12 10:15:59 +0000
commit07f1f5864204dfdf455067def863fcd20c8c6a26 (patch)
treeb2d3869a468de9bce1405b394b832aa711865806 /src/mm-modem-helpers.c
parent311d6f389e74899bc1790928bb44e8361e411a1b (diff)
modem-helpers: rework AT string quote operation and add unit tests
Rework the AT string quote operation to build the output with the GString helper, instead of manually calculating how many bytes we'll need in the output. It just makes it clearer.
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r--src/mm-modem-helpers.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 44e8e71e..8dad5a39 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -454,6 +454,34 @@ mm_bcd_to_string (const guint8 *bcd, gsize bcd_len, gboolean low_nybble_first)
/*****************************************************************************/
+gchar *
+mm_at_quote_string (const gchar *input)
+{
+ GString *str;
+ gsize input_len;
+
+ input_len = input ? strlen (input) : 0;
+ str = g_string_sized_new (3 + 3 * input_len); /* worst case */
+ g_string_append_c (str, '"');
+
+ if (input) {
+ gsize i, len;
+
+ len = strlen (input);
+ for (i = 0 ; i < len; i++) {
+ if (input[i] < 0x20 || input[i] == '"' || input[i] == '\\')
+ g_string_append_printf (str, "\\%02X", input[i]);
+ else
+ g_string_append_c (str, input[i]);
+ }
+ }
+ g_string_append_c (str, '"');
+
+ return g_string_free (str, FALSE);
+}
+
+/*****************************************************************************/
+
GRegex *
mm_voice_ring_regex_get (void)
{