aboutsummaryrefslogtreecommitdiff
path: root/src/mm-at-serial-port.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mm-at-serial-port.c')
-rw-r--r--src/mm-at-serial-port.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/mm-at-serial-port.c b/src/mm-at-serial-port.c
index 4a5afa4b..c16e8786 100644
--- a/src/mm-at-serial-port.c
+++ b/src/mm-at-serial-port.c
@@ -49,6 +49,32 @@ typedef struct {
/*****************************************************************************/
+gchar *
+mm_at_serial_port_quote_string (const char *string)
+{
+ int len, i;
+ gchar *quoted, *pos;
+
+ if (string == NULL)
+ len = 0;
+ else
+ len = strlen (string);
+ quoted = g_malloc (3 + 3 * len); /* worst case */
+
+ pos = quoted;
+ *pos++ = '"';
+ for (i = 0 ; i < len; i++) {
+ if (string[i] < 0x20 || string[i] == '"' || string[i] == '\\')
+ pos += sprintf (pos, "\\%02X", string[i]);
+ else
+ *pos++ = string[i];
+ }
+ *pos++ = '"';
+ *pos++ = '\0';
+
+ return quoted;
+}
+
void
mm_at_serial_port_set_response_parser (MMAtSerialPort *self,
MMAtSerialResponseParserFn fn,