[asterisk-commits] rizzo: trunk r93950 - in /trunk: include/asterisk/strings.h main/utils.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 19 11:09:01 CST 2007


Author: rizzo
Date: Wed Dec 19 11:09:01 2007
New Revision: 93950

URL: http://svn.digium.com/view/asterisk?view=rev&rev=93950
Log:
Add a new API function, written at least twice in app_voicemail.c
and likely in other places too.

This is quite useful when placing mail/html stuff in config files.

 /*!
   \brief Convert some C escape sequences (\b\f\n\r\t) into the
        equivalent characters.
   \brief s The string to be converted (will be modified).
   \return The converted string.
  */
 char *ast_unescape_c(char *s);
 



Modified:
    trunk/include/asterisk/strings.h
    trunk/main/utils.c

Modified: trunk/include/asterisk/strings.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/strings.h?view=diff&rev=93950&r1=93949&r2=93950
==============================================================================
--- trunk/include/asterisk/strings.h (original)
+++ trunk/include/asterisk/strings.h Wed Dec 19 11:09:01 2007
@@ -155,6 +155,14 @@
 char *ast_unescape_semicolon(char *s);
 
 /*!
+  \brief Convert some C escape sequences (\b\f\n\r\t) into the
+	equivalent characters.
+  \brief s The string to be converted (will be modified).
+  \return The converted string.
+ */
+char *ast_unescape_c(char *s);
+
+/*!
   \brief Size-limited null-terminating string copy.
   \arg dst The destination buffer.
   \arg src The source string

Modified: trunk/main/utils.c
URL: http://svn.digium.com/view/asterisk/trunk/main/utils.c?view=diff&rev=93950&r1=93949&r2=93950
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Wed Dec 19 11:09:01 2007
@@ -1020,6 +1020,43 @@
 	return s;
 }
 
+/* !\brief unescape some C sequences in place, return pointer to the original string.
+ */
+char *ast_unescape_c(char *src)
+{
+	char c, *ret, *dst;
+
+	if (src == NULL)
+		return NULL;
+	for (ret = dst = src; (c = *src++); *dst++ = c ) {
+		if (c != '\\')
+			continue;	/* copy char at the end of the loop */
+		switch ((c = *src++)) {
+		case '\0':	/* special, trailing '\' */
+			c = '\\';
+			break;
+		case 'b':	/* backspace */
+			c = '\b';
+			break;
+		case 'f':	/* form feed */
+			c = '\f';
+			break;
+		case 'n':
+			c = '\n';
+			break;
+		case 'r':
+			c = '\r';
+			break;
+		case 't':
+			c = '\t';
+			break;
+		}
+		/* default, use the char literally */
+	}
+	*dst = '\0';
+	return ret;
+}
+
 int ast_build_string_va(char **buffer, size_t *space, const char *fmt, va_list ap)
 {
 	int result;




More information about the asterisk-commits mailing list