mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 22:31:28 +02:00
[MINOR] Add cut_crlf(), ltrim(), rtrim() and alltrim()
Add four generic functions.
This commit is contained in:
parent
4483d43c66
commit
3d5562b96c
@ -282,6 +282,49 @@ extern int strl2ic(const char *s, int len);
|
|||||||
extern int strl2irc(const char *s, int len, int *ret);
|
extern int strl2irc(const char *s, int len, int *ret);
|
||||||
extern int strl2llrc(const char *s, int len, long long *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
|
/* 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
|
* 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
|
* function intead of localtime() because that one requires a time_t* which
|
||||||
|
Loading…
x
Reference in New Issue
Block a user