]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] Add cut_crlf(), ltrim(), rtrim() and alltrim()
authorKrzysztof Piotr Oledzki <ole@ans.pl>
Sat, 10 Oct 2009 18:11:17 +0000 (20:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 10 Oct 2009 19:51:16 +0000 (21:51 +0200)
Add four generic functions.

include/common/standard.h

index 715ed240bc0eac8cfdb4b8919a273f2e5e0a9a54..ce70f2e5fa8ae855274a94c2d388a89d047d7b17 100644 (file)
@@ -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 <now> 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