MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / SDL_IntPrecisionAdjust

Function SDL_IntPrecisionAdjust

deps/SDL2/src/stdlib/SDL_string.c:1457–1492  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1455}
1456
1457static void
1458SDL_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
1494static size_t
1495SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)

Callers 4

SDL_PrintLongFunction · 0.85
SDL_PrintUnsignedLongFunction · 0.85
SDL_PrintLongLongFunction · 0.85

Calls 3

SDL_strlenFunction · 0.85
SDL_memmoveFunction · 0.85
SDL_memsetFunction · 0.85

Tested by

no test coverage detected