You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Laurent Charmet <la...@atempo.com> on 2012/02/16 13:22:38 UTC

[BUG?] apr_strnatcasecmp with space/blank

Hi all,

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. "


I just want a portable strcasecmp/stricmp

Regards

note: View in apr 1.4.2 and reproduce with 1.4.6

Re: [BUG?] apr_strnatcasecmp with space/blank

Posted by Laurent Charmet <la...@atempo.com>.
strcasecmp macro is perfect.

Perhaps a documentation update will be interesting to avoid confusion.

Thx a lot

Laurent

On 02/16/2012 02:45 PM, Philip Martin wrote:
> apr_general.h appears to ensure that strcasecmp is available,
> providing one if the system does not. Perhaps you could use that? 

Re: [BUG?] apr_strnatcasecmp with space/blank

Posted by Philip Martin <ph...@codematters.co.uk>.
Laurent Charmet <la...@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