| 1455 | } |
| 1456 | |
| 1457 | static void |
| 1458 | SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) |
| 1459 | {/* left-pad num with zeroes. */ |
| 1460 | size_t sz, pad, have_sign; |
| 1461 | |
| 1462 | if (!info) |
| 1463 | return; |
| 1464 | |
| 1465 | have_sign = 0; |
| 1466 | if (*num == '-' || *num == '+') { |
| 1467 | have_sign = 1; |
| 1468 | ++num; |
| 1469 | --maxlen; |
| 1470 | } |
| 1471 | sz = SDL_strlen(num); |
| 1472 | if (info->precision > 0 && sz < (size_t)info->precision) { |
| 1473 | pad = (size_t)info->precision - sz; |
| 1474 | if (pad + sz + 1 <= maxlen) { /* otherwise ignore the precision */ |
| 1475 | SDL_memmove(num + pad, num, sz + 1); |
| 1476 | SDL_memset(num, '0', pad); |
| 1477 | } |
| 1478 | } |
| 1479 | info->precision = -1;/* so that SDL_PrintString() doesn't make a mess. */ |
| 1480 | |
| 1481 | if (info->pad_zeroes && info->width > 0 && (size_t)info->width > sz + have_sign) { |
| 1482 | /* handle here: spaces are added before the sign |
| 1483 | but zeroes must be placed _after_ the sign. */ |
| 1484 | /* sz hasn't changed: we ignore pad_zeroes if a precision is given. */ |
| 1485 | pad = (size_t)info->width - sz - have_sign; |
| 1486 | if (pad + sz + 1 <= maxlen) { |
| 1487 | SDL_memmove(num + pad, num, sz + 1); |
| 1488 | SDL_memset(num, '0', pad); |
| 1489 | } |
| 1490 | info->width = 0; /* so that SDL_PrintString() doesn't make a mess. */ |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | static size_t |
| 1495 | SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value) |
no test coverage detected