mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 04:30:28 +00:00
Fix up utils nonsense
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include <arpa/inet.h> /* we want to override inet_ntoa */
|
#include <arpa/inet.h> /* we want to override inet_ntoa */
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "asterisk/lock.h"
|
#include "asterisk/lock.h"
|
||||||
|
|
||||||
@@ -135,21 +136,59 @@ struct ast_hostent {
|
|||||||
\param str the input string
|
\param str the input string
|
||||||
\return a pointer to the first non-whitespace character
|
\return a pointer to the first non-whitespace character
|
||||||
*/
|
*/
|
||||||
|
#ifdef LOW_MEMORY
|
||||||
char *ast_skip_blanks(char *str);
|
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.
|
\brief Trims trailing whitespace characters from a string.
|
||||||
\param str the input string
|
\param str the input string
|
||||||
\return a pointer to the NULL following the string
|
\return a pointer to the NULL following the string
|
||||||
*/
|
*/
|
||||||
|
#ifdef LOW_MEMORY
|
||||||
char *ast_trim_blanks(char *str);
|
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.
|
\brief Gets a pointer to first whitespace character in a string.
|
||||||
\param str the input string
|
\param str the input string
|
||||||
\return a pointer to the first whitespace character
|
\return a pointer to the first whitespace character
|
||||||
*/
|
*/
|
||||||
|
#ifdef LOW_MEMORY
|
||||||
char *ast_skip_nonblanks(char *str);
|
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.
|
\brief Strip leading/trailing whitespace from a string.
|
||||||
@@ -160,7 +199,17 @@ char *ast_skip_nonblanks(char *str);
|
|||||||
characters from the input string, and returns a pointer to
|
characters from the input string, and returns a pointer to
|
||||||
the resulting string. The string is modified in place.
|
the resulting string. The string is modified in place.
|
||||||
*/
|
*/
|
||||||
|
#ifdef LOW_MEMORY
|
||||||
char *ast_strip(char *s);
|
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.
|
\brief Strip leading/trailing whitespace and quotes from a string.
|
||||||
|
17
utils.c
17
utils.c
@@ -37,6 +37,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|||||||
static char base64[64];
|
static char base64[64];
|
||||||
static char b2a[256];
|
static char b2a[256];
|
||||||
|
|
||||||
|
#ifdef LOW_MEMORY
|
||||||
char *ast_skip_blanks(char *str)
|
char *ast_skip_blanks(char *str)
|
||||||
{
|
{
|
||||||
while (*str && *str < 33)
|
while (*str && *str < 33)
|
||||||
@@ -48,13 +49,18 @@ char *ast_trim_blanks(char *str)
|
|||||||
{
|
{
|
||||||
char *work = str;
|
char *work = str;
|
||||||
|
|
||||||
if (work && !ast_strlen_zero(work)) {
|
if (work) {
|
||||||
work += strlen(work) - 1;
|
work += strlen(work) - 1;
|
||||||
while ((work >= str) && *work && *work < 33)
|
/* It's tempting to only want to erase after we exit this loop,
|
||||||
work--;
|
but since ast_trim_blanks *could* receive a constant string
|
||||||
*(++work) = '\0'; /* terminate 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 work;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ast_skip_nonblanks(char *str)
|
char *ast_skip_nonblanks(char *str)
|
||||||
@@ -71,6 +77,7 @@ char *ast_strip(char *s)
|
|||||||
ast_trim_blanks(s);
|
ast_trim_blanks(s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
char *ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
|
char *ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user