Skip to content

Commit

Permalink
delete support for unimplemented float specifiers (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesnicholson authored Jul 26, 2019
1 parent 18f5168 commit 7636270
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 42 deletions.
39 changes: 3 additions & 36 deletions nanoprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ typedef enum {
#endif
#if NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS == 1
,
NPF_FMT_SPEC_CONV_FLOAT_DECIMAL, /* 'f', 'F' */
NPF_FMT_SPEC_CONV_FLOAT_EXPONENT, /* 'e', 'E' */
NPF_FMT_SPEC_CONV_FLOAT_DYNAMIC, /* 'g', 'G' */
NPF_FMT_SPEC_CONV_FLOAT_HEXPONENT /* 'a', 'A' */
NPF_FMT_SPEC_CONV_FLOAT_DECIMAL /* 'f', 'F' */
#endif
} npf__format_spec_conversion_t;

Expand Down Expand Up @@ -471,30 +468,6 @@ int npf__parse_format_spec(char const *format, npf__format_spec_t *out_spec) {
out_spec->conv_spec = NPF_FMT_SPEC_CONV_FLOAT_DECIMAL;
out_spec->conv_spec_case = NPF_FMT_SPEC_CONV_CASE_UPPER;
break;
case 'e':
out_spec->conv_spec = NPF_FMT_SPEC_CONV_FLOAT_EXPONENT;
out_spec->conv_spec_case = NPF_FMT_SPEC_CONV_CASE_LOWER;
break;
case 'E':
out_spec->conv_spec = NPF_FMT_SPEC_CONV_FLOAT_EXPONENT;
out_spec->conv_spec_case = NPF_FMT_SPEC_CONV_CASE_UPPER;
break;
case 'a':
out_spec->conv_spec = NPF_FMT_SPEC_CONV_FLOAT_HEXPONENT;
out_spec->conv_spec_case = NPF_FMT_SPEC_CONV_CASE_LOWER;
break;
case 'A':
out_spec->conv_spec = NPF_FMT_SPEC_CONV_FLOAT_HEXPONENT;
out_spec->conv_spec_case = NPF_FMT_SPEC_CONV_CASE_UPPER;
break;
case 'g':
out_spec->conv_spec = NPF_FMT_SPEC_CONV_FLOAT_DYNAMIC;
out_spec->conv_spec_case = NPF_FMT_SPEC_CONV_CASE_LOWER;
break;
case 'G':
out_spec->conv_spec = NPF_FMT_SPEC_CONV_FLOAT_DYNAMIC;
out_spec->conv_spec_case = NPF_FMT_SPEC_CONV_CASE_UPPER;
break;
#endif
#if NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS == 1
case 'n':
Expand Down Expand Up @@ -536,12 +509,9 @@ int npf__parse_format_spec(char const *format, npf__format_spec_t *out_spec) {
break;
#if NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS == 1
case NPF_FMT_SPEC_CONV_FLOAT_DECIMAL:
case NPF_FMT_SPEC_CONV_FLOAT_EXPONENT:
case NPF_FMT_SPEC_CONV_FLOAT_DYNAMIC:
case NPF_FMT_SPEC_CONV_FLOAT_HEXPONENT:
#endif
out_spec->precision = 6;
break;
#endif
}
}
#endif
Expand Down Expand Up @@ -988,10 +958,7 @@ int npf_vpprintf(npf_putc pc, void *pc_ctx, char const *format, va_list vlist) {
#endif

#if NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS == 1
case NPF_FMT_SPEC_CONV_FLOAT_DECIMAL: /* 'f', 'F' */
case NPF_FMT_SPEC_CONV_FLOAT_EXPONENT: /* 'e', 'E' */
case NPF_FMT_SPEC_CONV_FLOAT_DYNAMIC: /* 'g', 'G' */
case NPF_FMT_SPEC_CONV_FLOAT_HEXPONENT: { /* 'a', 'A' */
case NPF_FMT_SPEC_CONV_FLOAT_DECIMAL: { /* 'f', 'F' */
float val;
if (fs.length_modifier ==
NPF_FMT_SPEC_LEN_MOD_LONG_DOUBLE) {
Expand Down
20 changes: 14 additions & 6 deletions unit_tests/test_parse_format_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,16 @@ TEST(npf__parse_format_spec, PrecisionDefaultIsSixIfFloat) {
CHECK_EQUAL(2, npf__parse_format_spec("%f", &spec));
CHECK_EQUAL(NPF_FMT_SPEC_PRECISION_NONE, spec.precision_type);
CHECK_EQUAL(6, spec.precision);
CHECK_EQUAL(2, npf__parse_format_spec("%g", &spec));
CHECK_EQUAL(NPF_FMT_SPEC_PRECISION_NONE, spec.precision_type);
CHECK_EQUAL(6, spec.precision);
CHECK_EQUAL(2, npf__parse_format_spec("%e", &spec));
CHECK_EQUAL(NPF_FMT_SPEC_PRECISION_NONE, spec.precision_type);
CHECK_EQUAL(6, spec.precision);
/*
Not supported yet
CHECK_EQUAL(2, npf__parse_format_spec("%g", &spec));
CHECK_EQUAL(NPF_FMT_SPEC_PRECISION_NONE, spec.precision_type);
CHECK_EQUAL(6, spec.precision);
CHECK_EQUAL(2, npf__parse_format_spec("%e", &spec));
CHECK_EQUAL(NPF_FMT_SPEC_PRECISION_NONE, spec.precision_type);
CHECK_EQUAL(6, spec.precision);
*/
}

TEST(npf__parse_format_spec, PrecisionStar) {
Expand Down Expand Up @@ -463,6 +467,9 @@ TEST(npf__parse_format_spec, F) {
CHECK_EQUAL(NPF_FMT_SPEC_CONV_CASE_UPPER, spec.conv_spec_case);
}

/*
Not implemented yet
TEST(npf__parse_format_spec, e) {
CHECK_EQUAL(2, npf__parse_format_spec("%e", &spec));
CHECK_EQUAL(NPF_FMT_SPEC_CONV_FLOAT_EXPONENT, spec.conv_spec);
Expand Down Expand Up @@ -498,4 +505,5 @@ TEST(npf__parse_format_spec, G) {
CHECK_EQUAL(NPF_FMT_SPEC_CONV_FLOAT_DYNAMIC, spec.conv_spec);
CHECK_EQUAL(NPF_FMT_SPEC_CONV_CASE_UPPER, spec.conv_spec_case);
}
*/

0 comments on commit 7636270

Please sign in to comment.