After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 774124 - ascii_strto* are declared private
ascii_strto* are declared private
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings: GLib
0.34.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 669278 789179 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2016-11-09 00:14 UTC by Daniel Espinosa
Modified: 2017-11-20 20:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add an optional 'unparsed' parameter to double.try_parse() to return the unparsed part of the string (1.03 KB, patch)
2016-11-09 13:11 UTC, Al Thomas
none Details | Review
Test program for new optional parameter in double.try_parse () (840 bytes, text/x-vala)
2016-11-09 13:12 UTC, Al Thomas
  Details
Test program for new optional parameter in double.try_parse () (904 bytes, text/plain)
2016-11-09 13:17 UTC, Al Thomas
  Details
glib-2.0: Add optional 'unparsed' parameter to *.try_parse () (3.48 KB, patch)
2017-03-10 07:55 UTC, Rico Tzschichholz
committed Details | Review

Description Daniel Espinosa 2016-11-09 00:14:03 UTC
For basic types like double, ascii_strto* are declared as private methods. They should be public.
Comment 1 Al Thomas 2016-11-09 10:45:02 UTC
For double the g_ascii_strtod function signature has been adapted with a Vala wrapper. So you would use double.parse ("1.2"); or double.try_parse ("1.2", result); The try_parse () method will return true if successful and the double in result. Does this not work for you?
Comment 2 Daniel Espinosa 2016-11-09 12:19:44 UTC
For GSVG[1] I use ascii_strtod to parse numbers like "3.45mm". With this function I parse first part to get double value and output pointer used to generate a enum value to know its units, then no is not enough.
Comment 3 Rico Tzschichholz 2016-11-09 12:33:01 UTC
These methods are bound as string.to_*()
Comment 4 Al Thomas 2016-11-09 13:11:12 UTC
Created attachment 339392 [details] [review]
Add an optional 'unparsed' parameter to double.try_parse() to return the unparsed part of the string
Comment 5 Al Thomas 2016-11-09 13:12:38 UTC
Created attachment 339393 [details]
Test program for new optional parameter in double.try_parse ()

Program tests the original signature and new signature both work with the amended binding.
Comment 6 Al Thomas 2016-11-09 13:17:59 UTC
Created attachment 339394 [details]
Test program for new optional parameter in double.try_parse ()

Program tests the original signature and new signature both work with the amended binding. This version also prints the double returned.
Comment 7 Daniel Espinosa 2016-11-09 17:25:14 UTC
Its Ok for me.

Can be this backported to 0.34?
Comment 8 Rico Tzschichholz 2017-03-10 07:55:28 UTC
Created attachment 347598 [details] [review]
glib-2.0: Add optional 'unparsed' parameter to *.try_parse ()

This reintroduces a dropped feature of string.to_*() while returning the
maybe available unparsed part of the string.
Comment 9 Al Thomas 2017-03-10 12:01:21 UTC
Review of attachment 347598 [details] [review]:

This looks fine to me and keeps backwards compatibility by making the unparsed argument optional.
Although strtoll applies to int64, strtoull applies to uint64 and strtod applies to double, it
would be nice if Vala had a consistent API for all number types it supports. I'm not finding standard
C functions for that. So Vala may need to generate the C code itself. Is this a good idea?
Comment 10 Daniel Espinosa 2017-03-10 14:49:59 UTC
Review of attachment 347598 [details] [review]:

It is good  fore. Can be backported to 0.34?
Comment 11 Daniel Espinosa 2017-03-10 14:58:28 UTC
(In reply to Al Thomas from comment #9)
> Review of attachment 347598 [details] [review] [review]:
> 
> This looks fine to me and keeps backwards compatibility by making the
> unparsed argument optional.
> Although strtoll applies to int64, strtoull applies to uint64 and strtod
> applies to double, it
> would be nice if Vala had a consistent API for all number types it supports.
> I'm not finding standard
> C functions for that. So Vala may need to generate the C code itself. Is
> this a good idea?

I think Vala can use standard C methods and GLib ones, mark as unstable until we have confidence on C code is secure enough.
Comment 12 Al Thomas 2017-10-18 23:18:07 UTC
*** Bug 789179 has been marked as a duplicate of this bug. ***
Comment 13 Al Thomas 2017-10-18 23:18:36 UTC
*** Bug 669278 has been marked as a duplicate of this bug. ***
Comment 14 Daniel Espinosa 2017-10-19 14:43:52 UTC
Can you, please push, this patch to upstream?

I need it for GSVG development.
Comment 15 Rico Tzschichholz 2017-11-20 20:04:52 UTC
Attachment 347598 [details] pushed as 1eb5044 - glib-2.0: Add optional 'unparsed' parameter to *.try_parse ()