[Asterisk-cvs] asterisk/include/asterisk utils.h,1.35,1.36
markster at lists.digium.com
markster at lists.digium.com
Sat Jun 18 07:53:29 CDT 2005
Update of /usr/cvsroot/asterisk/include/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv5157/include/asterisk
Modified Files:
utils.h
Log Message:
Fix up utils nonsense
Index: utils.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/utils.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- utils.h 17 Jun 2005 13:25:01 -0000 1.35
+++ utils.h 18 Jun 2005 11:54:38 -0000 1.36
@@ -20,6 +20,7 @@
#include <arpa/inet.h> /* we want to override inet_ntoa */
#include <netdb.h>
#include <limits.h>
+#include <string.h>
#include "asterisk/lock.h"
@@ -135,21 +136,59 @@
\param str the input string
\return a pointer to the first non-whitespace character
*/
+#ifdef LOW_MEMORY
char *ast_skip_blanks(char *str);
+#else
+static inline char *ast_skip_blanks(char *str)
+{
+ while (*str && *str < 33)
+ str++;
+ return str;
+}
+#endif
/*!
\brief Trims trailing whitespace characters from a string.
\param str the input string
\return a pointer to the NULL following the string
*/
+#ifdef LOW_MEMORY
char *ast_trim_blanks(char *str);
+#else
+static inline char *ast_trim_blanks(char *str)
+{
+ char *work = str;
+
+ if (work) {
+ work += strlen(work) - 1;
+ /* It's tempting to only want to erase after we exit this loop,
+ but since ast_trim_blanks *could* receive a constant string
+ (which we presumably wouldn't have to touch), we shouldn't
+ actually set anything unless we must, and it's easier just
+ to set each position to \0 than to keep track of a variable
+ for it */
+ while ((work >= str) && *work < 33)
+ *(work--) = '\0';
+ }
+ return str;
+}
+#endif
/*!
\brief Gets a pointer to first whitespace character in a string.
\param str the input string
\return a pointer to the first whitespace character
*/
+#ifdef LOW_MEMORY
char *ast_skip_nonblanks(char *str);
+#else
+static inline char *ast_skip_nonblanks(char *str)
+{
+ while (*str && *str > 32)
+ str++;
+ return str;
+}
+#endif
/*!
\brief Strip leading/trailing whitespace from a string.
@@ -160,7 +199,17 @@
characters from the input string, and returns a pointer to
the resulting string. The string is modified in place.
*/
+#ifdef LOW_MEMORY
char *ast_strip(char *s);
+#else
+static inline char *ast_strip(char *s)
+{
+ s = ast_skip_blanks(s);
+ if (s)
+ ast_trim_blanks(s);
+ return s;
+}
+#endif
/*!
\brief Strip leading/trailing whitespace and quotes from a string.
More information about the svn-commits
mailing list