bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Please add strrstr


From: Bruno Haible
Subject: Re: Please add strrstr
Date: Sat, 2 Aug 2008 11:08:39 +0200
User-agent: KMail/1.5.4

Hi,

Reuben Thomas wrote:
> strrstr, which is to strstr as strrchr is to strchr, is a useful and 
> moderately widely-used function.

Is it useful? Like strstr, is works on strings of bytes, not characters.
I.e. if it is applied to strings of characters, the result is wrong in
multibyte locales whose encoding is e.g. BIG5 or GB18030 (two frequently used
locale encodings in Taiwan and China, respectively).

Additionally, the implementation that you have in zile-2.2.60/src/strrstr.c
has a worst-case quadratic running time, i.e. a program that uses is can appear
to be hung for long times if the inputs happen to be unlucky. Whereas the
strstr function in glibc and gnulib is worst-case linear.

How widely used is it? Among the OSes, only HP-UX provides it. Google for
  strrstr      -> 4530 hits    / 9000 hits
  pthread_join -> 138000 hits  / 58300 hits
  fgetwc       -> 34500 hits   / 5000 hits
To me, that counts as "rarely used".

> I'd be happy to see it in gnulib. Any chance of that? What do I 
> need to do, if so?

I would like to see an 'strrstr' in gnulib only if there is also an
'mbsrstr' - a multibyte-character aware reverse search. Otherwise people are
tempted to use functions that don't work in Chinese environments.

And both implementations should be worst-case linear and should have a
testsuite.

What you can do? Look at the gnulib modules strstr, strstr-tests, mbsstr,
mbsstr-tests, and submit similar code for the reverse search. If you are
not very familiar with the way gnulib modules are written, you can omit the
*.m4 macros; we can do that for you.

Bruno





reply via email to

[Prev in Thread] Current Thread [Next in Thread]