SDL_vsnprintf() updates for zero-padding:
authorOzkan Sezer <sezeroz@gmail.com>
Thu, 27 Sep 2018 09:37:36 +0300
changeset 1224008b190d518fc
parent 12239 55489adbb75c
child 12241 f72836cfb92b
SDL_vsnprintf() updates for zero-padding:

- remove force-enabling of pad_zeroes for %u for compatibility
(was added in https://hg.libsdl.org/SDL/rev/701f4a25df89)
- ignore pad_zeroes for %s and %S
- ignore pad_zeroes for %d, %i and %u if a precision is given
src/stdlib/SDL_string.c
     1.1 --- a/src/stdlib/SDL_string.c	Wed Sep 26 20:10:32 2018 -0400
     1.2 +++ b/src/stdlib/SDL_string.c	Thu Sep 27 09:37:36 2018 +0300
     1.3 @@ -1415,7 +1415,7 @@
     1.4  
     1.5  static void
     1.6  SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
     1.7 -{/* left-pad num with zeroes, if needed. */
     1.8 +{/* left-pad num with zeroes. */
     1.9      size_t sz, pad;
    1.10  
    1.11      if (!info || info->precision < 0)
    1.12 @@ -1681,6 +1681,9 @@
    1.13                      break;
    1.14                  case 'i':
    1.15                  case 'd':
    1.16 +                    if (info.precision >= 0) {
    1.17 +                        info.pad_zeroes = SDL_FALSE;
    1.18 +                    }
    1.19                      switch (inttype) {
    1.20                      case DO_INT:
    1.21                          len = SDL_PrintLong(text, left, &info,
    1.22 @@ -1718,7 +1721,9 @@
    1.23                      }
    1.24                      /* Fall through to unsigned handling */
    1.25                  case 'u':
    1.26 -                    info.pad_zeroes = SDL_TRUE;
    1.27 +                    if (info.precision >= 0) {
    1.28 +                        info.pad_zeroes = SDL_FALSE;
    1.29 +                    }
    1.30                      switch (inttype) {
    1.31                      case DO_INT:
    1.32                          len = SDL_PrintUnsignedLong(text, left, &info,
    1.33 @@ -1745,12 +1750,14 @@
    1.34                          /* In practice this is used on Windows for WCHAR strings */
    1.35                          wchar_t *wide_arg = va_arg(ap, wchar_t *);
    1.36                          char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg));
    1.37 +                        info.pad_zeroes = SDL_FALSE;
    1.38                          len = SDL_PrintString(text, left, &info, arg);
    1.39                          SDL_free(arg);
    1.40                          done = SDL_TRUE;
    1.41                      }
    1.42                      break;
    1.43                  case 's':
    1.44 +                    info.pad_zeroes = SDL_FALSE;
    1.45                      len = SDL_PrintString(text, left, &info, va_arg(ap, char *));
    1.46                      done = SDL_TRUE;
    1.47                      break;