Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | cri@tiac.net (Richard Harter) |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: how to use regex library |
| Date | 2011-05-25 05:27 +0000 |
| Message-ID | <4ddc820b.462513963@text.giganews.com> (permalink) |
| References | (8 earlier) <slrnitarbh.pff.usenet-nospam@guild.seebs.net> <4dd5822c.3772884@text.giganews.com> <CLedndmZB91nAkvQnZ2dnUVZ_q6dnZ2d@bestweb.net> <4ddabab0.345938784@text.giganews.com> <P4GdnYrWMoKaRUbQnZ2dnUVZ_g6dnZ2d@bestweb.net> |
On Tue, 24 May 2011 12:08:43 -0400, Kenneth Brody
<kenbrody@spamcop.net> wrote:
>On 5/23/2011 5:16 PM, Richard Harter wrote:
>> On Fri, 20 May 2011 13:08:14 -0400, Kenneth Brody
>> <kenbrody@spamcop.net> wrote:
>[...]
>>> If all you pass it is a regex and a buffer pointer, why would you expect it
>>> to do a "get next" on the second call? If you expect the answer to be
>>> "because I passed the _same_ pointer both times, so it should 'know' I meant
>>> to do 'get next' on it", then how would you ever use it in a loop where the
>>> same buffer is passed, though the contents have changed? (For example,
>>> something like "grep", which would print any line that has a match to the
>>> regex.)
>>
>> You seem to be just saying "it won't work" without actually thinking
>> it out.
>
>Well, by "work", I require more functionality than simply an implicit "next"
>ability by passing the same parameters repeatedly. (See below.)
Codswallop. (See below.)
>
>> The issue at hand is the possibility of a regexec based
>> search that is passed a buffer address; each time it is called with
>> the same buffer address it returns the next match until there are no
>> more matches. There are three separate issues - can it be done,
>> should it be done, and is it reasonable to expect it.
>>
>> The "can it be done" is fairly trivial. What is needed is a bit of
>> memory. One way to do it is to have two pointers, one to the buffer
>[...]
>> If no match is found we reset to (0,0) and return no match. If a
>> match is found we (a) reinitialize if the buffer is exhausted, or
>> (b)we set the next search point. That done, we return the found match.
>
>Sure, it "can be done". The problem with that approach is there is no way
>for force a restart. Unless, of course, you include an "init" call, which
>is what this thread assumes is lacking.
>
>It is not unreasonable to reuse the same buffer on multiple searches,
>including the possibility that a subsequent call will contain the same data
>in the buffer, despite wanting to restart the search.
Now really, you should try a little harder than that. The obvious way
to force a restart is to pass in a buffer address of 0.
Since you seem to have difficulty coming up with a valid objection,
let me help you. Consider what happens if you have two buffers, call
them a and b, and you want to alternate between them. First you
search a and get the its first match. Next you search b and get its
first match. Now you go back to a to get its second match. Oops,
you've just reset the stored buffer so you get the first match.
So, have we shown that the scheme doesn't work. No, we haven't. We
could do what we would have to do anyway your "pass in the current
start point", namely pass in the current start point.
What we have shown is that we cannot consistently rely on the scheme
to do the right thing by default. In other words the magic only works
some of the time. That's the argument you should have been making.
>
>[...]
>> Finally, "is it reasonable to expect it?" That depends. For
>> implementers who are wedded to the thought that "buffer" must be the
>> search point, probably not. For users who want a bit of convenience,
>> probably.
>
>I, personally, find a function which does an implicit "next", without any
>way to explicitly "init", very distasteful. That is, of course, just my
>personal opinion, though it is based on 27+ years of using and writing
>enumerator functions in C. YMMV.
Since your objections were specious they provide no legitimate basis
for distaste. On the other hand, your personal opinions are data. In
my 28+ years of using and writing C my view has been that it is better
to think things out instead of relying on gut emotion. YMMV.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-17 23:11 -0400
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-18 03:33 +0000
Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-18 06:41 -0400
Re: how to use regex library James Kuyper <jameskuyper@verizon.net> - 2011-05-18 08:00 -0400
Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-18 20:00 +0100
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-18 19:44 +0000
Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-19 00:43 +0100
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 00:52 +0000
Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-18 22:04 -0400
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 02:21 +0000
Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-19 04:04 +0100
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 03:14 +0000
Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-19 12:03 +0100
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 14:37 +0000
Re: how to use regex library Geoff <geoff@invalid.invalid> - 2011-05-19 11:29 -0700
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 19:08 +0000
Re: how to use regex library Geoff <geoff@invalid.invalid> - 2011-05-19 12:11 -0700
Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-20 12:55 -0400
Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-19 04:01 +0100
Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-19 16:02 +0000
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 16:34 +0000
Re: how to use regex library Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-19 13:59 -0700
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 22:06 +0000
Re: how to use regex library Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-24 02:03 -0700
Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-20 13:14 -0400
Re: how to use regex library Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-24 02:16 -0700
Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-19 14:37 -0400
Re: how to use regex library James Kuyper <jameskuyper@verizon.net> - 2011-05-18 19:44 -0400
Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-19 03:49 +0100
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 03:03 +0000
Re: how to use regex library Ike Naar <ike@iceland.freeshell.org> - 2011-05-19 06:48 +0000
Re: how to use regex library James Kuyper <jameskuyper@verizon.net> - 2011-05-19 05:58 -0400
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 14:37 +0000
Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-19 14:48 -0400
Re: how to use regex library Shao Miller <sha0.miller@gmail.com> - 2011-05-19 15:05 -0400
Re: how to use regex library Mark Bluemel <mark_bluemel@pobox.com> - 2011-05-18 13:36 +0100
Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-18 13:13 -0400
Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-18 22:13 -0400
Re: how to use regex library Mark Bluemel <mark_bluemel@pobox.com> - 2011-05-19 08:55 +0100
Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-19 07:59 -0400
Re: how to use regex library Keith Thompson <kst-u@mib.org> - 2011-05-19 08:50 -0700
Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-19 15:12 -0400
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 19:40 +0000
Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-19 20:58 +0000
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 22:06 +0000
Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-20 01:01 +0000
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-20 01:57 +0000
Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-20 13:27 -0400
Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-20 13:08 -0400
Re: how to use regex library Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-20 18:54 +0100
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-20 19:14 +0000
Re: how to use regex library Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-21 00:04 +0100
Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-23 12:42 -0400
Re: how to use regex library Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-23 20:16 +0100
Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-23 21:16 +0000
Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-24 12:08 -0400
Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-25 05:27 +0000
Re: how to use regex library Michael Press <rubrum@pacbell.net> - 2011-05-22 21:41 -0700
Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-23 21:33 +0000
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-18 16:03 +0000
Re: how to use regex library Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-05-18 14:05 +0000
Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-20 22:06 -0400
Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-21 03:49 +0000
Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-21 20:25 -0400
Re: how to use regex library Shao Miller <sha0.miller@gmail.com> - 2011-05-21 13:17 -0500
csiph-web