Fixed SDL printf output for 0x%.8x
authorSam Lantinga <slouken@libsdl.org>
Tue, 23 Jul 2013 12:44:14 -0700
changeset 7503 701f4a25df89
parent 7502 6ff02ff3cf06
child 7504 5a45a9536a65
Fixed SDL printf output for 0x%.8x
src/stdlib/SDL_string.c
--- a/src/stdlib/SDL_string.c	Tue Jul 23 08:06:49 2013 -0700
+++ b/src/stdlib/SDL_string.c	Tue Jul 23 12:44:14 2013 -0700
@@ -1308,7 +1308,24 @@
 static size_t
 SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
 {
-    return SDL_strlcpy(text, string, maxlen);
+    size_t length = 0;
+
+    if (info && info->width && (size_t)info->width > SDL_strlen(string)) {
+        char fill = info->pad_zeroes ? '0' : ' ';
+        size_t width = info->width - SDL_strlen(string);
+        while (width-- > 0 && maxlen > 0) {
+            *text++ = fill;
+            ++length;
+            --maxlen;
+        }
+    }
+
+    length += SDL_strlcpy(text, string, maxlen);
+
+    if (info && info->do_lowercase) {
+        SDL_strlwr(text);
+    }
+    return length;
 }
 
 static size_t
@@ -1572,6 +1589,7 @@
                     }
                     /* Fall through to unsigned handling */
                 case 'u':
+                    info.pad_zeroes = SDL_TRUE;
                     switch (inttype) {
                     case DO_INT:
                         len = SDL_PrintUnsignedLong(text, left, &info,
@@ -1587,12 +1605,6 @@
                                                         va_arg(ap, Uint64));
                         break;
                     }
-                    if (info.do_lowercase) {
-                        size_t i;
-                        for (i = 0; i < len && i < left; ++i) {
-                            text[i] = SDL_tolower((unsigned char)text[i]);
-                        }
-                    }
                     done = SDL_TRUE;
                     break;
                 case 'f':