minmea_scan("f"): allow spaces at the start of the field
This commit is contained in:
parent
b777fbe0b9
commit
e81f908109
5
minmea.c
5
minmea.c
@ -166,6 +166,11 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
||||
scale *= 10;
|
||||
} else if (*field == '.' && scale == 0) {
|
||||
scale = 1;
|
||||
} else if (*field == ' ') {
|
||||
/* Allow spaces at the start of the field. Not NMEA
|
||||
* conformant, but some modules do this. */
|
||||
if (sign != 0 || value != -1 || scale != 0)
|
||||
goto parse_error;
|
||||
} else {
|
||||
goto parse_error;
|
||||
}
|
||||
|
12
tests.c
12
tests.c
@ -181,6 +181,18 @@ START_TEST(test_minmea_scan_f)
|
||||
ck_assert(minmea_scan("foo,12.3", "_;f", &f) == true);
|
||||
ck_assert_int_eq(f.value, 123);
|
||||
ck_assert_int_eq(f.scale, 10);
|
||||
|
||||
/* accept spaces at the start of the field. some modules do this, unfortunately. */
|
||||
ck_assert(minmea_scan(" -1.23,V", "f", &f) == true);
|
||||
ck_assert_int_eq(f.value, -123);
|
||||
ck_assert_int_eq(f.scale, 100);
|
||||
ck_assert(minmea_scan(" -4.56,V", "f", &f) == true);
|
||||
ck_assert_int_eq(f.value, -456);
|
||||
ck_assert_int_eq(f.scale, 100);
|
||||
ck_assert(minmea_scan("-3.33 ,V", "f", &f) == false);
|
||||
ck_assert(minmea_scan(" -3.33 ,V", "f", &f) == false);
|
||||
ck_assert(minmea_scan("-3. 33,V", "f", &f) == false);
|
||||
ck_assert(minmea_scan("0 .0,V", "f", &f) == false);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user