Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing '+12345' as a float #77

Closed
TD22057 opened this issue Aug 8, 2022 · 3 comments
Closed

Error parsing '+12345' as a float #77

TD22057 opened this issue Aug 8, 2022 · 3 comments

Comments

@TD22057
Copy link

TD22057 commented Aug 8, 2022

Version 1.1.2

#include <iostream>
#include <string_view>
#include <cstdio>
#include <scn/scn.h>

int main()
{
   const char* s = "+12345";
   std::string_view sv( s );
   
   double x;
   auto r = scn::scan( sv, "{}", x );
   if ( r ) std::cout << "scn: got: " << x << "\n";
   else std::cout << "scn: error: '" << r.error().msg() << "'\n";

   if ( sscanf( s, "%lf", &x ) == 1 ) std::cout << "scanf: got: " << x << "\n";
   else std::cout << "scanf: error\n";
         
   return 0;
}

yields:

scn: error: 'fast_float'
scanf: got: 12345

IMO this should work and return 12345. It's also a bit annoying that the error message just says "fast_float" instead of indicating what the problem is. Obviously I can guess what the problem is but when this is embedded in a larger application the user will have no idea what fast_float means.

@ilynxy
Copy link

ilynxy commented Oct 5, 2023

According to https://github.com/fastfloat/fast_float and https://en.cppreference.com/w/cpp/utility/from_chars a leading '+' sign is forbidden.
IMO, leading '+' sign should be parsed with scnlib.

@TD22057
Copy link
Author

TD22057 commented Oct 5, 2023

Fair enough.

Is there any chance the error message could be improved? I'd be happy to help but the level of template programming used is more than I'm used to at least without some direction.

@eliaskosunen
Copy link
Owner

This works properly in v2, and is now also fixed properly in the latest master. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants