[LIBC] Modfied Version of sscanf
Garrett Cooper
yanegomi at gmail.com
Mon May 2 16:23:45 UTC 2011
On Mon, May 2, 2011 at 8:57 AM, Arnaud Lacombe <lacombar at gmail.com> wrote:
> Hi,
>
> On Mon, May 2, 2011 at 8:13 AM, Martin Möller
> <moeller.akt at googlemail.com> wrote:
>> Hello,
>>
>> Thanks for all the replies.
>> We have so far discovered the following suggetions for the parsing Problem:
>> Using:
>> o a tokenizer/parser is too much overhead for such a simple task
Explain :).
>> o strchr, memchr is too low-level and not elegant enough
You forgot strstr ;D!
>> o strtok would not even parse (tokenize) this simple example
Yes, it could. It just wouldn't be smart to set the delim up as " "
more than once ;D (wrong tool for the job)...
>> o a regexp library: How would you solve the problem with a regexp lib ?
'^[A-Z]{3,4} (.+) HTTP/[\d\.]+$'
Example:
$ python
>>> import re
>>> r = re.compile('^[A-Z]{3,4} (.+) HTTP/[\d\.]+$')
>>> m = r.match('GET blah_HTTP/1.1.1.1.1.1_whatever HTTP/1.1')
>>> m.group(1)
'blah_HTTP/1.1.1.1.1.1_whatever
I don't think it's what you wanted earlier -- but you can inspect the
request string further if you wish (and should!).
Oh yeah, and although I used python as a quick and dirty means for
illustrating my example, there's no reason why you can't use C, C++,
Java, perl, ruby, etc to articulate what you need.
Point is, there are a ton of different solutions available, and the
fact that one is homing in on sscanf as the tool to solve the problem
is probably ill put, just like using strtok/strsep wouldn't be the
best choice either for this problem by itself.
Cheers,
-Garrett
More information about the freebsd-hackers
mailing list