diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/buffer.c | 6 | ||||
-rw-r--r-- | common/stringx.c | 29 | ||||
-rw-r--r-- | common/stringx.h | 9 |
3 files changed, 40 insertions, 4 deletions
diff --git a/common/buffer.c b/common/buffer.c index 72f0b6c..5a77922 100644 --- a/common/buffer.c +++ b/common/buffer.c @@ -1,6 +1,7 @@ #include "usuals.h" #include "httpauthd.h" +#include "stringx.h" #include <syslog.h> @@ -316,10 +317,7 @@ char* ha_bufparseline(ha_buffer_t* buf, int trim) buf->_pp = t + 1; if(trim) - { - while(t > line && isspace(*(--t))) - *t = 0; - } + line = trim_space(line); /* We don't return empty strings */ if(line[0] == 0) diff --git a/common/stringx.c b/common/stringx.c new file mode 100644 index 0000000..159a7f4 --- /dev/null +++ b/common/stringx.c @@ -0,0 +1,29 @@ + +#include <string.h> +#include "stringx.h" + +const char* trim_start(const char* data) +{ + while(*data && isspace(*data)) + ++data; + return data; +} + +char* trim_end(char* data) +{ + char* t = data + strlen(data); + + while(t > data && isspace(*(t - 1))) + { + t--; + *t = 0; + } + + return data; +} + +char* trim_space(char* data) +{ + data = (char*)trim_start(data); + return trim_end(data); +} diff --git a/common/stringx.h b/common/stringx.h new file mode 100644 index 0000000..4776170 --- /dev/null +++ b/common/stringx.h @@ -0,0 +1,9 @@ + +#ifndef __STRINGX_H__ +#define __STRINGX_H__ + +const char* trim_start(const char* data); +char* trim_end(char* data); +char* trim_space(char* data); + +#endif /* __STRINGX_H__ */ |