diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h index 1a1751597..6e3848f49 100644 --- a/include/haproxy/tools.h +++ b/include/haproxy/tools.h @@ -915,6 +915,8 @@ void calltrace(char *fmt, ...); /* same as strstr() but case-insensitive */ const char *strnistr(const char *str1, int len_str1, const char *str2, int len_str2); +int strordered(const char *s1, const char *s2, const char *s3); + /* after increasing a pointer value, it can exceed the first buffer * size. This function transform the value of according with * the expected position. is an array of the one or two diff --git a/src/tools.c b/src/tools.c index 34f86321c..5d5e1b02d 100644 --- a/src/tools.c +++ b/src/tools.c @@ -4363,6 +4363,15 @@ const char *strnistr(const char *str1, int len_str1, const char *str2, int len_s return NULL; } +/* Returns true if s1 < s2 < s3 otherwise zero. Both s1 and s3 may be NULL and + * in this case only non-null strings are compared. This allows to pass initial + * values in iterators and in sort functions. + */ +int strordered(const char *s1, const char *s2, const char *s3) +{ + return (!s1 || strcmp(s1, s2) < 0) && (!s3 || strcmp(s2, s3) < 0); +} + /* This function read the next valid utf8 char. * is the byte srray to be decode, is its length. * The function returns decoded char encoded like this: