Date: Mon, 2 May 2011 09:23:43 -0700 From: Garrett Cooper <yanegomi@gmail.com> To: Arnaud Lacombe <lacombar@gmail.com> Cc: freebsd-hackers@freebsd.org, =?ISO-8859-1?Q?Martin_M=F6ller?= <moeller.akt@googlemail.com> Subject: Re: [LIBC] Modfied Version of sscanf Message-ID: <BANLkTimS%2BU7D7yZ8gO7Pw3ZOQC35_c8V-w@mail.gmail.com> In-Reply-To: <BANLkTinJVG=%2BUq5rc=FdS6WueQSJmDxuaA@mail.gmail.com> References: <20110501162925.GB47497@stack.nl> <C9E46C77.389%moeller.akt@googlemail.com> <BANLkTinJVG=%2BUq5rc=FdS6WueQSJmDxuaA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, May 2, 2011 at 8:57 AM, Arnaud Lacombe <lacombar@gmail.com> wrote: > Hi, > > On Mon, May 2, 2011 at 8:13 AM, Martin M=F6ller > <moeller.akt@googlemail.com> wrote: >> Hello, >> >> Thanks for all the replies. >> We have so far discovered the following suggetions for the parsing Probl= em: >> Using: >> =A0 =A0o a tokenizer/parser is too much overhead for such a simple task Explain :). >> =A0 =A0o strchr, memchr is too low-level and not elegant enough You forgot strstr ;D! >> =A0 =A0o 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)... >> =A0 =A0o a regexp library: How would you solve the problem with a regexp= lib ? '^[A-Z]{3,4} (.+) HTTP/[\d\.]+$' Example: $ python >>> import re >>> r =3D re.compile('^[A-Z]{3,4} (.+) HTTP/[\d\.]+$') >>> m =3D 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BANLkTimS%2BU7D7yZ8gO7Pw3ZOQC35_c8V-w>