Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #3672

Re: memmem()

Path csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail
NNTP-Posting-Date Tue, 10 May 2011 03:27:37 -0500
Message-ID <4DC8F6F9.3C1@mindspring.com> (permalink)
Date Tue, 10 May 2011 04:27:37 -0400
From pete <pfiland@mindspring.com>
Reply-To pfiland@mindspring.com
Organization PF
X-Mailer Mozilla 3.04Gold (WinNT; I)
MIME-Version 1.0
Newsgroups comp.lang.c
Subject Re: memmem()
References <iq50jo$aue$1@dont-email.me> <87pqnrkel5.fsf@blp.benpfaff.org> <pan.2011.05.10.06.19.19.15000@nowhere.com> <87mxivhxl5.fsf@temporary-address.org.uk>
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
Lines 54
X-Usenet-Provider http://www.giganews.com
NNTP-Posting-Host 4.154.220.173
X-Trace sv3-aKL5T9rZB2E49k6cVeVDNa3wPVIY7vKd8z7uCyzHu8FKFTWwBsRWKxJjAacVnQuhrW8GPUPDC2saiXo!WoRaRx/cXuFCZeI0HcqkME6jbzvwF3tkVlK502mKEW0Kitek9B7AYFVbiWmKtiCJausKOKjvgVpC!UVoPzF+ZKQ==
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2380
Xref x330-a1.tempe.blueboxinc.net comp.lang.c:3672

Show key headers only | View raw


Dr Nick wrote:
 
> I've got "caseless_strcmp" in my code, built on strcasecmp (and, on
> porting to Windows, stricmp)
> 
> Thusly:
> 
> #ifdef HAVE_STRCASECMP
>   #define caseless_strcmp(x,y) strcasecmp(x,y)
> #else
>   #ifdef HAVE_STRICMP
>     #define caseless_strcmp(x,y) stricmp(x,y)
>   #else
>     #error Need to implement caseless string comparison here
>   #endif
> #endif
> 
> So I push the problem off for the time being,
> avoid writing code I don't
> need to, but don't leave anyone porting it in the future to a non GNU
> system foundering with no idea of what has gone wrong.


This is what I have so far:

#include <ctype.h>

int str_ccmp(const char *s1, const char *s2)
{
    for (;;) {
        if (*s1 != *s2) {
            const int c1 = tolower(*(const unsigned char *)s1);
            const int c2 = tolower(*(const unsigned char *)s2);

            if (c2 != c1) {
                return c2 > c1 ? -1 : 1;
            }
        } else {
            if (*s1 == '\0') {
                return 0;
            }
        }
        ++s1;
        ++s2;
    }
}

I'm still not sure whether it's better to use
    tolower(*(const unsigned char *)s1)
or
    tolower((unsigned char)*s1)

-- 
pete

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

memmem() barcaroller <barcaroller@music.net> - 2011-05-07 22:53 -0400
  Re: memmem() "Bill Cunningham" <nospam@nspam.invalid> - 2011-05-08 02:33 -0400
  Re: memmem() puppi <fabricio.puppi@gmail.com> - 2011-05-08 00:11 -0700
    Re: memmem() "Bill Cunningham" <nospam@nspam.invalid> - 2011-05-08 04:36 -0400
    Re: memmem() James Kuyper <jameskuyper@verizon.net> - 2011-05-08 09:33 -0400
      Re: memmem() barcaroller <barcaroller@music.net> - 2011-05-08 10:48 -0400
    Re: memmem() barcaroller <barcaroller@gmail.com> - 2011-05-08 10:46 -0400
      Re: memmem() Angel <angel+news@spamcop.net> - 2011-05-08 15:56 +0000
        Re: memmem() barcaroller <barcaroller@music.net> - 2011-05-08 12:03 -0400
          Re: memmem() puppi <fabricio.puppi@gmail.com> - 2011-05-09 04:58 -0700
            Re: memmem() Keith Thompson <kst-u@mib.org> - 2011-05-09 08:45 -0700
      Re: memmem() puppi <fabricio.puppi@gmail.com> - 2011-05-09 04:47 -0700
  Re: memmem() blp@cs.stanford.edu (Ben Pfaff) - 2011-05-09 09:45 -0700
    Re: memmem() Nobody <nobody@nowhere.com> - 2011-05-10 07:19 +0100
      Re: memmem() Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-10 07:35 +0100
        Re: memmem() pete <pfiland@mindspring.com> - 2011-05-10 04:27 -0400
      Re: memmem() Ben Pfaff <blp@cs.stanford.edu> - 2011-05-10 07:16 -0700
        Re: memmem() Nobody <nobody@nowhere.com> - 2011-05-10 21:07 +0100

csiph-web