string/whitespace handling cleanups (bug #4449, with mods)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5924 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2005-06-17 13:25:01 +00:00
parent fb6f36387f
commit 9a80a7bc2c
3 changed files with 143 additions and 192 deletions

35
utils.c
View File

@@ -37,15 +37,36 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
static char base64[64];
static char b2a[256];
char *ast_skip_blanks(char *str)
{
while (*str && *str < 33)
str++;
return str;
}
char *ast_trim_blanks(char *str)
{
if (str) {
str += strlen(str) - 1;
while (*str && *str < 33)
str--;
*(++str) = '\0'; /* terminate string */
}
return str;
}
char *ast_skip_nonblanks(char *str)
{
while (*str && *str > 32)
str++;
return str;
}
char *ast_strip(char *s)
{
char *e;
while (*s && (*s < 33)) s++;
e = s + strlen(s) - 1;
while ((e > s) && (*e < 33)) e--;
*++e = '\0';
s = ast_skip_blanks(s);
if (s)
ast_trim_blanks(s);
return s;
}