From: Krzysztof Piotr Oledzki Date: Sat, 10 Oct 2009 18:11:17 +0000 (+0200) Subject: [MINOR] Add cut_crlf(), ltrim(), rtrim() and alltrim() X-Git-Tag: v1.4-dev4~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d5562b96ce91b75d468f8d50ad0d1c2df4ddc6f;p=thirdparty%2Fhaproxy.git [MINOR] Add cut_crlf(), ltrim(), rtrim() and alltrim() Add four generic functions. --- diff --git a/include/common/standard.h b/include/common/standard.h index 715ed240bc..ce70f2e5fa 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -282,6 +282,49 @@ extern int strl2ic(const char *s, int len); extern int strl2irc(const char *s, int len, int *ret); extern int strl2llrc(const char *s, int len, long long *ret); +static inline char *cut_crlf(char *s) { + + while (*s != '\r' || *s == '\n') { + char *p = s++; + + if (!*p) + return p; + } + + *s++ = 0; + + return s; +} + +static inline char *ltrim(char *s, char c) { + + if (c) + while (*s == c) + s++; + + return s; +} + +static inline char *rtrim(char *s, char c) { + + char *p = s + strlen(s); + + while (p-- > s) + if (*p == c) + *p = '\0'; + else + break; + + return s; +} + +static inline char *alltrim(char *s, char c) { + + rtrim(s, c); + + return ltrim(s, c); +} + /* This function converts the time_t value into a broken out struct tm * which must be allocated by the caller. It is highly recommended to use this * function intead of localtime() because that one requires a time_t* which