apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philip Martin <phi...@codematters.co.uk>
Subject Re: [BUG?] apr_strnatcasecmp with space/blank
Date Thu, 16 Feb 2012 13:45:32 GMT
Laurent Charmet <laurent.charmet@atempo.com> writes:

> I have an issue with the function apr_strnatcasecmp(). Take a look at
> gdb output:
>
> 5719                                if (apr_strnatcasecmp(type_str,
> p_list[i].name) == 0) {
> (gdb)
> 5720                                    service = (DEDUP_SERVICE_TYPE_T)
> (p_list[i].type & 0xFF);
> (gdb) p type_str
> $4 = 0x62ca4d "Webserver"
> (gdb) p p_list[i].name
> $5 = 0x634ff0 "Web server"
>
> So "Webserver" equal "Web server" ?!
>
> I suspect that blank act as a separator and that "Web" equal "Web"
>
> In the source there is this comment concerning "numeric string":
>
> /* Compare, recognizing numeric string and ignoring case. */
> APR_DECLARE(int) apr_strnatcasecmp(char const *a, char const *b)
> {
>      return strnatcmp0(a, b, 1);
> }
>
> I hope it's a comment error because in the online documentation it's:
>
> "Do a natural order comparison of two strings ignoring the case of the
> strings. "

APR doesn't define 'natural' order.  From the implementation it appears
to be about skipping whitespace and numerical ordering so the string
ordering "1", "11", "5", "55" has a natural order "1", "5", "11", "55".

apr_general.h appears to ensure that strcasecmp is available, providing
one if the system does not.  Perhaps you could use that?

-- 
Philip

Mime
View raw message