From owner-freebsd-hackers@FreeBSD.ORG Mon May 2 16:23:45 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4B00C1065670 for ; Mon, 2 May 2011 16:23:45 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-vw0-f54.google.com (mail-vw0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id EFED78FC14 for ; Mon, 2 May 2011 16:23:44 +0000 (UTC) Received: by vws18 with SMTP id 18so5763466vws.13 for ; Mon, 02 May 2011 09:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=S7odBqxBKF9Tno3rG/EsIdt512Pw3EX0D3ExABK/6+g=; b=boshEJbxdbqG0MHWHnKjYtPe7fL2bQi2ywpok+4THGhkl0n5F3teXUiZItDwXS07YY EzBTrnopVPvuDV8K5VbcRJLlBAtUJmcu1+80H7qPncoqRmlsbJLuKqHy05EMdaUVnWZa HKujGENMjiNiF9ohipD7OgzmTMuqSzco6gy3w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=hlXD9EDdzlqFxjCKpTnhQ3Vf/zwsJDAwVGWa8y2V1cb2VeW9/vBrPircKzDrWVKDRW DAo9wDi+jIn1mV4UQQ9gbW2+l7p/jGO5l/jjY11QuNhWEoDGOccfFYFN3S0JL800OJAf Nh2Q4ltrzp2i0d55YpdfqKxdk0tqARSAHASVE= MIME-Version: 1.0 Received: by 10.220.112.138 with SMTP id w10mr1720388vcp.46.1304353424016; Mon, 02 May 2011 09:23:44 -0700 (PDT) Received: by 10.220.199.130 with HTTP; Mon, 2 May 2011 09:23:43 -0700 (PDT) In-Reply-To: References: <20110501162925.GB47497@stack.nl> Date: Mon, 2 May 2011 09:23:43 -0700 Message-ID: From: Garrett Cooper To: Arnaud Lacombe Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org, =?ISO-8859-1?Q?Martin_M=F6ller?= Subject: Re: [LIBC] Modfied Version of sscanf X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 May 2011 16:23:45 -0000 On Mon, May 2, 2011 at 8:57 AM, Arnaud Lacombe wrote: > Hi, > > On Mon, May 2, 2011 at 8:13 AM, Martin M=F6ller > 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