| 1 |
|
| /* stencil_expfix.h - two-digit exponents everywhere. |
| 2 |
|
| * |
| 3 |
|
| * C99 prints at least two exponent digits (1.5e+03); the Windows CRT prints |
| 4 |
|
| * three (1.5e+003), and the fmt filter's float path goes through that CRT |
| 5 |
|
| * on purpose (see stencil_filters.c). Dropping the leading zero of a |
| 6 |
|
| * three-digit exponent gives the same bytes on every platform; a real |
| 7 |
|
| * three-digit exponent (1e+100) has no leading zero and is kept. Perl-free |
| 8 |
|
| * so it can be unit-tested on its own. |
| 9 |
|
| */ |
| 10 |
|
| #ifndef STENCIL_EXPFIX_H |
| 11 |
|
| #define STENCIL_EXPFIX_H |
| 12 |
|
| |
| 13 |
|
| #include <string.h> |
| 14 |
|
| |
| 15 |
|
| /* s is NUL-terminated with len bytes before the NUL; returns the new len. */ |
| 16 |
0 |
| static int stencil_expfix(char *s, int len) |
| 17 |
|
| { |
| 18 |
|
| int i; |
| 19 |
0 |
▶ | for (i = 0; i + 4 < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i + 4 < len; i++) { |
0 |
0 |
0 |
|
| 20 |
0 |
▶ | if ((s[i] == 'e' || s[i] == 'E') |
Branch: 2 branches
| Branch | True | False | Total |
| if ((s[i] == 'e' || s[i] == 'E') |
0 |
0 |
0 |
| if ((s[i] == 'e' || s[i] == 'E') |
0 |
0 |
0 |
|
| 21 |
0 |
▶ | && (s[i + 1] == '+' || s[i + 1] == '-') |
Branch: 2 branches
| Branch | True | False | Total |
| && (s[i + 1] == '+' || s[i + 1] == '-') |
0 |
0 |
0 |
| && (s[i + 1] == '+' || s[i + 1] == '-') |
0 |
0 |
0 |
|
| 22 |
0 |
▶ | && s[i + 2] == '0' |
Branch: 1 branch
| Branch | True | False | Total |
| && s[i + 2] == '0' |
0 |
0 |
0 |
|
| 23 |
0 |
▶ | && s[i + 3] >= '0' && s[i + 3] <= '9' |
Branch: 2 branches
| Branch | True | False | Total |
| && s[i + 3] >= '0' && s[i + 3] <= '9' |
0 |
0 |
0 |
| && s[i + 3] >= '0' && s[i + 3] <= '9' |
0 |
0 |
0 |
|
| 24 |
0 |
▶ | && s[i + 4] >= '0' && s[i + 4] <= '9') { |
Branch: 2 branches
| Branch | True | False | Total |
| && s[i + 4] >= '0' && s[i + 4] <= '9') { |
0 |
0 |
0 |
| && s[i + 4] >= '0' && s[i + 4] <= '9') { |
0 |
0 |
0 |
|
| 25 |
0 |
| memmove(s + i + 2, s + i + 3, (size_t)(len - (i + 3)) + 1); |
| 26 |
0 |
| len--; |
| 27 |
|
| } |
| 28 |
|
| } |
| 29 |
0 |
| return len; |
| 30 |
|
| } |
| 31 |
|
| |
| 32 |
|
| #endif /* STENCIL_EXPFIX_H */ |