220 17949 <CANh-dXks9L3jx16ofDBto8RyjXyo+Lmd-a08PhdFNTdWUZVWqA@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: "'Jeffrey Yasskin' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Parsing Numbers
Date: Mon, 18 May 2015 13:12:00 -0700
Lines: 61
Approved: news@gmane.org
Message-ID: <CANh-dXks9L3jx16ofDBto8RyjXyo+Lmd-a08PhdFNTdWUZVWqA@mail.gmail.com>
References: <eb5c19d6-074f-4ee4-8e2d-6d92349eb4be@isocpp.org> <CANh-dXnfgYUt-6SDQn6vvcsUFSDWP3RicAHoZdvBjVUwLJuKzQ@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1431979945 18799 80.91.229.3 (18 May 2015 20:12:25 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 18 May 2015 20:12:25 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDDM34EO6QDRBJMP5GVAKGQEDMM7III@isocpp.org Mon May 18 22:12:25 2015
Return-path: <std-proposals+bncBDDM34EO6QDRBJMP5GVAKGQEDMM7III@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pd0-f200.google.com ([209.85.192.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDDM34EO6QDRBJMP5GVAKGQEDMM7III@isocpp.org>)
	id 1YuROh-0008C0-Lf
	for gclcip-std-proposals@m.gmane.org; Mon, 18 May 2015 22:12:23 +0200
Original-Received: by pdlj11 with SMTP id j11sf407334817pdl.0
        for <gclcip-std-proposals@m.gmane.org>; Mon, 18 May 2015 13:12:22 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=eD2ASBP8p+Y3mN/vEiD3pUqKv4JOr0AvxNbmvCZvSQE=;
        b=EkXhxVA312flK02V7c1lVGbZPKNoJbOicocx0cbEST9DHHVCAQdmMBPVbcM5Y1Yqu7
         0p/aJ3SQHVNMxj2YH0mqX4a/2cL3fUrsGVsvyqL68XMfE6TVhltvlZrIh22MI+ZVmQ5E
         Subog/QKcDM+o0W6t0S3E8Yeu7ns63umwGxFu1ZB5AdMf2v4dWeYb+SrxwoEAhLOteQh
         FHVfoKpvdsBaCJ1PraKiNU67mimcKbzNajJ/jNRCtJbKvdXtoPmjTWZ446Ur1WQOUYtR
         rQTwExyAe+umFq0CF8sEwlmzME1pqOiOYLsUHqLQOEgwv5ghxEbPdgF09Sv6cBewfBR4
         VioA==
X-Gm-Message-State: ALoCoQlt2NIj7MASe+9Au1A6IQWqyCslq7EdqAQk97mRlNYLbA9EWEGdgW6WHm/kgUYfUbu+fSIo
X-Received: by 10.66.121.164 with SMTP id ll4mr34903398pab.19.1431979942399;
        Mon, 18 May 2015 13:12:22 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.51.17.44 with SMTP id gb12ls761021igd.34.gmail; Mon, 18 May
 2015 13:12:21 -0700 (PDT)
X-Received: by 10.50.138.74 with SMTP id qo10mr16858979igb.39.1431979941671;
        Mon, 18 May 2015 13:12:21 -0700 (PDT)
Original-Received: from mail-ie0-x236.google.com (mail-ie0-x236.google.com. [2607:f8b0:4001:c03::236])
        by mx.google.com with ESMTPS id l1si9771944ict.78.2015.05.18.13.12.21
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 18 May 2015 13:12:21 -0700 (PDT)
Received-SPF: pass (google.com: domain of jyasskin@google.com designates 2607:f8b0:4001:c03::236 as permitted sender) client-ip=2607:f8b0:4001:c03::236;
Original-Received: by iesa3 with SMTP id a3so92851985ies.2
        for <std-proposals@isocpp.org>; Mon, 18 May 2015 13:12:21 -0700 (PDT)
X-Received: by 10.50.73.169 with SMTP id m9mr16749527igv.37.1431979941520;
 Mon, 18 May 2015 13:12:21 -0700 (PDT)
Original-Received: by 10.64.73.2 with HTTP; Mon, 18 May 2015 13:12:00 -0700 (PDT)
In-Reply-To: <CANh-dXnfgYUt-6SDQn6vvcsUFSDWP3RicAHoZdvBjVUwLJuKzQ@mail.gmail.com>
X-Original-Sender: jyasskin@google.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of jyasskin@google.com designates 2607:f8b0:4001:c03::236 as permitted
 sender) smtp.mail=jyasskin@google.com;       dkim=pass header.i=@google.com;
       dmarc=pass (p=REJECT dis=NONE) header.from=google.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
X-Original-From: Jeffrey Yasskin <jyasskin@google.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:17949
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17949>

On Mon, May 18, 2015 at 1:11 PM, Jeffrey Yasskin <jyasskin@google.com> wrote:
> Woot!
>
> On Mon, May 18, 2015 at 11:34 AM, Olaf van der Spek
> <olafvdspek@gmail.com> wrote:
>> Let's get the party started.
>>
>> What have we got?
>>
>> We've got functions like strtol and stoi which take a const char* or
>> std::string and return a number.
>>
>> long strtol(const char*, char **str_end, int base);
>> int  stoi(const std::string&, std::size_t* pos = 0, int base = 10);
>>
>> What do we want?
>>
>> Input should not be required to be null terminated, so string_view seems
>> like a suitable input type.
>> Error detection should be simpler, but not everyone is a fan of exceptions.
>
> Also, errors in parsing aren't generally exceptional.
>
>> And IMO skipping spaces should not be part of the parse function.
>
> +1. We should have a way to skip a string_view past spaces, but I
> agree that normal parsing should probably insist that the number
> appear at the start of the string.
>
>> There's also the question of what to do when not the entire input can be
>> parsed. Return an error or not.
>
> I believe "not", so that these functions can be used in parsing larger formats.
>
>> So, what about this one?
>>
>> optional<T> parse(string_view, std::size_t* pos = 0, int base = 10);
>>
>> An alternative could be:
>>
>> error_code parse(T&, string_view, std::size_t* pos = 0, int base = 10);
>
> I assume *pos gets the last position that was part of the parsed number?

Er, the position one after that.

> In the paper that proposes this, it'd be good to see examples of
> parsing code using each of the possible interfaces. That'll help
> produce a more informed decision than just looking at the interfaces
> abstractly.
>
> Jeffrey

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.
