src/stdlib/SDL_string.c
changeset 7503 701f4a25df89
parent 7482 249d8ecbbb7d
child 7728 800313a3533d
equal deleted inserted replaced
7502:6ff02ff3cf06 7503:701f4a25df89
  1306 } SDL_FormatInfo;
  1306 } SDL_FormatInfo;
  1307 
  1307 
  1308 static size_t
  1308 static size_t
  1309 SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
  1309 SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
  1310 {
  1310 {
  1311     return SDL_strlcpy(text, string, maxlen);
  1311     size_t length = 0;
       
  1312 
       
  1313     if (info && info->width && (size_t)info->width > SDL_strlen(string)) {
       
  1314         char fill = info->pad_zeroes ? '0' : ' ';
       
  1315         size_t width = info->width - SDL_strlen(string);
       
  1316         while (width-- > 0 && maxlen > 0) {
       
  1317             *text++ = fill;
       
  1318             ++length;
       
  1319             --maxlen;
       
  1320         }
       
  1321     }
       
  1322 
       
  1323     length += SDL_strlcpy(text, string, maxlen);
       
  1324 
       
  1325     if (info && info->do_lowercase) {
       
  1326         SDL_strlwr(text);
       
  1327     }
       
  1328     return length;
  1312 }
  1329 }
  1313 
  1330 
  1314 static size_t
  1331 static size_t
  1315 SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)
  1332 SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)
  1316 {
  1333 {
  1570                     if (info.radix == 10) {
  1587                     if (info.radix == 10) {
  1571                         info.radix = 8;
  1588                         info.radix = 8;
  1572                     }
  1589                     }
  1573                     /* Fall through to unsigned handling */
  1590                     /* Fall through to unsigned handling */
  1574                 case 'u':
  1591                 case 'u':
       
  1592                     info.pad_zeroes = SDL_TRUE;
  1575                     switch (inttype) {
  1593                     switch (inttype) {
  1576                     case DO_INT:
  1594                     case DO_INT:
  1577                         len = SDL_PrintUnsignedLong(text, left, &info,
  1595                         len = SDL_PrintUnsignedLong(text, left, &info,
  1578                                                     (unsigned long)
  1596                                                     (unsigned long)
  1579                                                     va_arg(ap, unsigned int));
  1597                                                     va_arg(ap, unsigned int));
  1585                     case DO_LONGLONG:
  1603                     case DO_LONGLONG:
  1586                         len = SDL_PrintUnsignedLongLong(text, left, &info,
  1604                         len = SDL_PrintUnsignedLongLong(text, left, &info,
  1587                                                         va_arg(ap, Uint64));
  1605                                                         va_arg(ap, Uint64));
  1588                         break;
  1606                         break;
  1589                     }
  1607                     }
  1590                     if (info.do_lowercase) {
       
  1591                         size_t i;
       
  1592                         for (i = 0; i < len && i < left; ++i) {
       
  1593                             text[i] = SDL_tolower((unsigned char)text[i]);
       
  1594                         }
       
  1595                     }
       
  1596                     done = SDL_TRUE;
  1608                     done = SDL_TRUE;
  1597                     break;
  1609                     break;
  1598                 case 'f':
  1610                 case 'f':
  1599                     len = SDL_PrintFloat(text, left, &info, va_arg(ap, double));
  1611                     len = SDL_PrintFloat(text, left, &info, va_arg(ap, double));
  1600                     done = SDL_TRUE;
  1612                     done = SDL_TRUE;