Fixed bug 2082 - SDL stdlib implementation does not force upper case for %X format specifier
authorSam Lantinga <slouken@libsdl.org>
Thu, 05 Sep 2013 06:59:34 -0700
changeset 7728800313a3533d
parent 7727 627ce8499c81
child 7729 384d5ba7ee44
Fixed bug 2082 - SDL stdlib implementation does not force upper case for %X format specifier

norfanin

When SDL_vsnprintf handles the %x format specifier, a boolean is set to signal forced lower case. It also should be able to signal forced upper case for the %X specifier. A boolean is not sufficient anymore. The attached patch adds an enum for the three cases: lower, upper and no change.
src/stdlib/SDL_string.c
     1.1 --- a/src/stdlib/SDL_string.c	Thu Sep 05 06:43:34 2013 -0700
     1.2 +++ b/src/stdlib/SDL_string.c	Thu Sep 05 06:59:34 2013 -0700
     1.3 @@ -1293,13 +1293,20 @@
     1.4  }
     1.5  #else
     1.6   /* FIXME: implement more of the format specifiers */
     1.7 +typedef enum
     1.8 +{
     1.9 +    SDL_CASE_NOCHANGE,
    1.10 +    SDL_CASE_LOWER,
    1.11 +    SDL_CASE_UPPER
    1.12 +} SDL_letter_case;
    1.13 +
    1.14  typedef struct
    1.15  {
    1.16      SDL_bool left_justify;
    1.17      SDL_bool force_sign;
    1.18      SDL_bool force_type;
    1.19      SDL_bool pad_zeroes;
    1.20 -    SDL_bool do_lowercase;
    1.21 +    SDL_letter_case force_case;
    1.22      int width;
    1.23      int radix;
    1.24      int precision;
    1.25 @@ -1322,8 +1329,12 @@
    1.26  
    1.27      length += SDL_strlcpy(text, string, maxlen);
    1.28  
    1.29 -    if (info && info->do_lowercase) {
    1.30 -        SDL_strlwr(text);
    1.31 +    if (info) {
    1.32 +        if (info->force_case == SDL_CASE_LOWER) {
    1.33 +            SDL_strlwr(text);
    1.34 +        } else if (info->force_case == SDL_CASE_UPPER) {
    1.35 +            SDL_strupr(text);
    1.36 +        }
    1.37      }
    1.38      return length;
    1.39  }
    1.40 @@ -1573,9 +1584,12 @@
    1.41                      break;
    1.42                  case 'p':
    1.43                  case 'x':
    1.44 -                    info.do_lowercase = SDL_TRUE;
    1.45 +                    info.force_case = SDL_CASE_LOWER;
    1.46                      /* Fall through to 'X' handling */
    1.47                  case 'X':
    1.48 +                    if (info.force_case == SDL_CASE_NOCHANGE) {
    1.49 +                        info.force_case = SDL_CASE_UPPER;
    1.50 +                    }
    1.51                      if (info.radix == 10) {
    1.52                          info.radix = 16;
    1.53                      }