[lexical_cast] Canonical representation for numbers?

Hello, does lexical_cast make some kind of guarantees on the output of arithmetic types cast as strings? I'm asking because I need to pass a lexical representation of integers and floats to the constructors of some 3rd party class that expects as input strings containing a certain representation of numbers. E.g., a float represented as string must be either in decimal or scientific notation, with "." as separator, "e" or "E" preceding the exponent, leading sign only in case of negative numbers and so on. So far I've used successfully lexical_cast for such purposes, but I'm wondering if other factors (e.g., locale) could alter the string representation of numbers. Is it safe to assume all numbers will always be cast in the same string structure regardless of platform, i18n, etc.? Cheers, Francesco.

On Monday, September 20, 2010, Francesco Biscani
Hello,
does lexical_cast make some kind of guarantees on the output of arithmetic types cast as strings?
I'm asking because I need to pass a lexical representation of integers and floats to the constructors of some 3rd party class that expects as input strings containing a certain representation of numbers. E.g., a float represented as string must be either in decimal or scientific notation, with "." as separator, "e" or "E" preceding the exponent, leading sign only in case of negative numbers and so on.
So far I've used successfully lexical_cast for such purposes, but I'm wondering if other factors (e.g., locale) could alter the string representation of numbers. Is it safe to assume all numbers will always be cast in the same string structure regardless of platform, i18n, etc.?
Cheers,
Francesco. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
you might want to look at Boost.Format. This gives you precise control over exact format. HTH - Rob. -- ACCU - Professionalism in programming - http://www.accu.org

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 09/20/2010 12:56 PM, Francesco Biscani wrote:
I'm asking because I need to pass a lexical representation of integers and floats to the constructors of some 3rd party class that expects as input strings containing a certain representation of numbers. E.g., a float represented as string must be either in decimal or scientific notation, with "." as separator, "e" or "E" preceding the exponent, leading sign only in case of negative numbers and so on.
Have you looked into Boost.Spirit? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyYETAACgkQO/fqqIuE2t41iACgwQ6D3T0Stbm7DAWc5aPvsQnW dkkAmgOZWoiknIpgIjG0XqTYY0LMZ/DX =+P9b -----END PGP SIGNATURE-----

Thanks all for the feedback!
I was hoping I could exploit lexical_cast's knowledge of floating
point types without having to write specific code, but it seems this
is not the case.
Didn't know about Boost.Format before, and I had no idea Spirit could
be used for this. I'm going to start digging into the docs.
Cheers,
Francesco.
On Tue, Sep 21, 2010 at 3:58 AM, Bryce Lelbach aka wash
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 09/20/2010 12:56 PM, Francesco Biscani wrote:
I'm asking because I need to pass a lexical representation of integers and floats to the constructors of some 3rd party class that expects as input strings containing a certain representation of numbers. E.g., a float represented as string must be either in decimal or scientific notation, with "." as separator, "e" or "E" preceding the exponent, leading sign only in case of negative numbers and so on.
Have you looked into Boost.Spirit? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkyYETAACgkQO/fqqIuE2t41iACgwQ6D3T0Stbm7DAWc5aPvsQnW dkkAmgOZWoiknIpgIjG0XqTYY0LMZ/DX =+P9b -----END PGP SIGNATURE----- _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Bryce Lelbach aka wash
-
Francesco Biscani
-
Robert Jones