mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-05-18 19:45:27 +00:00
MINOR: tools: add strordered() to check whether strings are ordered
When trying to sort sets of strings, it's often needed to required to compare 3 strings to see if the chosen one fits well between the two others. That's what this function does, in addition to being able to ignore extremities when they're NULL (typically for the first iteration for example).
This commit is contained in:
parent
29d799d591
commit
3ff476e9ef
@ -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 <ptr> according with
|
||||
* the expected position. <chunks> is an array of the one or two
|
||||
|
@ -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.
|
||||
* <s> is the byte srray to be decode, <len> is its length.
|
||||
* The function returns decoded char encoded like this:
|
||||
|
Loading…
Reference in New Issue
Block a user