* Parse each specifier based on this pattern:
%[flags][width][.precision][length]specifier
http://www.cplusplus.com/reference/cstdio/printf/
* Flags and width are still ignored.
* Precision is supported for strings (string precision is used by Pelion Client).
* Length is supported.
The printf(3) man page says "The functions snprintf() and vsnprintf() do
not write more than size bytes (including the terminating null byte
('\0')). If the output was truncated due to this limit, then the return
value is the number of characters (excluding the terminating null byte)
which would have been written to the final string if enough space had been
available." The last part of this spec (returning the number of
characters which would have been written to the string if enough space
had been available) was not implemented in minimal-printf. This PR
changes that by redirecting all the processed characters through the
"minimal_printf_putchar" helper function. This function will not write
to the buffer if there's no space left, but it will always increment the
number of written characters, in order to match the above description.
minimal_printf_putchar also contains checks for overflows, so these
checks are no longer needed in the rest of the code.
Other changes:
- In some cases, mbed_minimal_formatted_string didn't put the string
terminator in the output buffer. This PR ensures that this always
happens.
- Fixed a bug in printed hexadecimal numbers introduced by a previous
commit.
- Added buffer overflow tests for snprintf.
In the implementation, don't always display double hex digits when
printing with "%X". This is in line with the behaviour observed both
in mbed OS's printf (Newlib) and Linux's printf (glibc).
In the tests, always compare the baseline result with the result
returned by the minimal printf implementation, instead of comparing
with a constant value.