I want to parse a lot of Lat/Long coordinates with the following format 1.123456W or 50.123456N, basically a double followed by a char ('N', 'S', 'W', 'E'). I just want to remove the character from the string, convert to double and change the sign if its W-est or S-outh. The following code works in three out of four cases:
This works for 1.123456W, or 50.123456N, or 9.123456S, but not for 7.123456E. I'm guessing the Qi parser expects an E at the input string to correlate with an exponent representation of a double and fails because its incomplete? But how do I tell Qi to skip the exponent if it fails an just decodes the string to the point of where the E resides?
double d;
char c;
auto const expr = boost::spirit::qi::double_ >> boost::spirit::qi::char_;
std::string tok = "7.123456E";
bool success = boost::spirit::qi::parse( tok.cbegin(), tok.cend(), expr, d, c ) ) {
if( success ) {
if( c == 'W' || c == 'w' || c == 'S' || c == 'S' ) {
d = -d;
}
/// ....
}
Thank you very much!