mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-16 09:34:18 +00:00
feat(libc): add printf support for space padding
This patch makes printf capable of padding strings with spaces to their left, allowing right-aligning numeric values and strings. It uses the same width field for the format specifier as in the original libc function : %<width><type> (e.g.: %10d pads an integer value with spaces to the left to complete 10 characters). Change-Id: Ib7b5519dae17742181352ce58e507a05ba5250d4 Signed-off-by: Juan Pablo Conde <juanpablo.conde@arm.com>
This commit is contained in:
parent
e7486343d4
commit
0926d2df7a
1 changed files with 22 additions and 0 deletions
|
@ -95,6 +95,7 @@ static int unsigned_num_print(unsigned long long int unum, unsigned int radix,
|
|||
*
|
||||
* The following padding specifiers are supported by this print
|
||||
* %0NN - Left-pad the number with 0s (NN is a decimal number)
|
||||
* %NN - Left-pad the number with spaces (NN is a decimal number)
|
||||
*
|
||||
* The print exits on all other formats specifiers other than valid
|
||||
* combinations of the above specifiers.
|
||||
|
@ -182,6 +183,27 @@ loop:
|
|||
padn = 0;
|
||||
fmt++;
|
||||
|
||||
for (;;) {
|
||||
char ch = *fmt;
|
||||
if ((ch < '0') || (ch > '9')) {
|
||||
goto loop;
|
||||
}
|
||||
padn = (padn * 10) + (ch - '0');
|
||||
fmt++;
|
||||
}
|
||||
assert(0); /* Unreachable */
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
padc = ' ';
|
||||
padn = 0;
|
||||
|
||||
for (;;) {
|
||||
char ch = *fmt;
|
||||
if ((ch < '0') || (ch > '9')) {
|
||||
|
|
Loading…
Add table
Reference in a new issue