| 1409 | } SDL_FormatInfo; |
| 1410 | |
| 1411 | static size_t |
| 1412 | SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string) |
| 1413 | { |
| 1414 | size_t length = 0; |
| 1415 | size_t slen, sz; |
| 1416 | |
| 1417 | if (string == NULL) { |
| 1418 | string = "(null)"; |
| 1419 | } |
| 1420 | |
| 1421 | sz = SDL_strlen(string); |
| 1422 | if (info && info->width > 0 && (size_t)info->width > sz) { |
| 1423 | const char fill = info->pad_zeroes ? '0' : ' '; |
| 1424 | size_t width = info->width - sz; |
| 1425 | size_t filllen; |
| 1426 | |
| 1427 | if (info->precision >= 0 && (size_t)info->precision < sz) |
| 1428 | width += sz - (size_t)info->precision; |
| 1429 | |
| 1430 | filllen = SDL_min(width, maxlen); |
| 1431 | SDL_memset(text, fill, filllen); |
| 1432 | text += filllen; |
| 1433 | length += filllen; |
| 1434 | maxlen -= filllen; |
| 1435 | } |
| 1436 | |
| 1437 | slen = SDL_strlcpy(text, string, maxlen); |
| 1438 | length += SDL_min(slen, maxlen); |
| 1439 | |
| 1440 | if (info) { |
| 1441 | if (info->precision >= 0 && (size_t)info->precision < sz) { |
| 1442 | slen = (size_t)info->precision; |
| 1443 | if (slen < maxlen) { |
| 1444 | text[slen] = 0; |
| 1445 | length -= (sz - slen); |
| 1446 | } |
| 1447 | } |
| 1448 | if (info->force_case == SDL_CASE_LOWER) { |
| 1449 | SDL_strlwr(text); |
| 1450 | } else if (info->force_case == SDL_CASE_UPPER) { |
| 1451 | SDL_strupr(text); |
| 1452 | } |
| 1453 | } |
| 1454 | return length; |
| 1455 | } |
| 1456 | |
| 1457 | static void |
| 1458 | SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) |
no test coverage detected