SDL_vsnprintf: implemented '+' flag for signed integers printing.
authorOzkan Sezer <sezeroz@gmail.com>
Sat, 29 Sep 2018 01:24:10 +0300
changeset 12254f1ac9de30ee1
parent 12253 2dbf011db466
child 12255 d2e5d4520677
SDL_vsnprintf: implemented '+' flag for signed integers printing.

it is, of course, ignored for %u, %x, %o and %p.
src/stdlib/SDL_string.c
     1.1 --- a/src/stdlib/SDL_string.c	Sat Sep 29 00:51:24 2018 +0300
     1.2 +++ b/src/stdlib/SDL_string.c	Sat Sep 29 01:24:10 2018 +0300
     1.3 @@ -1361,7 +1361,7 @@
     1.4  typedef struct
     1.5  {
     1.6      SDL_bool left_justify; /* for now: ignored. */
     1.7 -    SDL_bool force_sign;   /* for now: used only by float printer, ignored otherwise. */
     1.8 +    SDL_bool force_sign;
     1.9      SDL_bool force_type;   /* for now: used only by float printer, ignored otherwise. */
    1.10      SDL_bool pad_zeroes;
    1.11      SDL_letter_case force_case;
    1.12 @@ -1453,9 +1453,13 @@
    1.13  static size_t
    1.14  SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)
    1.15  {
    1.16 -    char num[130];
    1.17 +    char num[130], *p = num;
    1.18  
    1.19 -    SDL_ltoa(value, num, info ? info->radix : 10);
    1.20 +    if (info->force_sign && value >= 0L) {
    1.21 +        *p++ = '+';
    1.22 +    }
    1.23 +
    1.24 +    SDL_ltoa(value, p, info ? info->radix : 10);
    1.25      SDL_IntPrecisionAdjust(num, maxlen, info);
    1.26      return SDL_PrintString(text, maxlen, info, num);
    1.27  }
    1.28 @@ -1473,9 +1477,13 @@
    1.29  static size_t
    1.30  SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value)
    1.31  {
    1.32 -    char num[130];
    1.33 +    char num[130], *p = num;
    1.34  
    1.35 -    SDL_lltoa(value, num, info ? info->radix : 10);
    1.36 +    if (info->force_sign && value >= (Sint64)0) {
    1.37 +        *p++ = '+';
    1.38 +    }
    1.39 +
    1.40 +    SDL_lltoa(value, p, info ? info->radix : 10);
    1.41      SDL_IntPrecisionAdjust(num, maxlen, info);
    1.42      return SDL_PrintString(text, maxlen, info, num);
    1.43  }
    1.44 @@ -1737,6 +1745,7 @@
    1.45                      }
    1.46                      /* Fall through to unsigned handling */
    1.47                  case 'u':
    1.48 +                    info.force_sign = SDL_FALSE;
    1.49                      if (info.precision >= 0) {
    1.50                          info.pad_zeroes = SDL_FALSE;
    1.51                      }