src/stdlib/SDL_string.c
changeset 11227 10b07421903d
parent 11052 0666dea591ab
child 11235 6c3895d3599f
equal deleted inserted replaced
11226:7f429e943ed3 11227:10b07421903d
    76         }
    76         }
    77         value *= radix;
    77         value *= radix;
    78         value += v;
    78         value += v;
    79         ++text;
    79         ++text;
    80     }
    80     }
    81     if (valuep) {
    81     if (valuep && text > textstart) {
    82         if (negative && value) {
    82         if (negative && value) {
    83             *valuep = -value;
    83             *valuep = -value;
    84         } else {
    84         } else {
    85             *valuep = value;
    85             *valuep = value;
    86         }
    86         }
   112         }
   112         }
   113         value *= radix;
   113         value *= radix;
   114         value += v;
   114         value += v;
   115         ++text;
   115         ++text;
   116     }
   116     }
   117     if (valuep) {
   117     if (valuep && text > textstart) {
   118         *valuep = value;
   118         *valuep = value;
   119     }
   119     }
   120     return (text - textstart);
   120     return (text - textstart);
   121 }
   121 }
   122 #endif
   122 #endif
   144         }
   144         }
   145         value *= radix;
   145         value *= radix;
   146         value += v;
   146         value += v;
   147         ++text;
   147         ++text;
   148     }
   148     }
   149     if (valuep) {
   149     if (valuep && text > textstart) {
   150         *valuep = value;
   150         *valuep = value;
   151     }
   151     }
   152     return (text - textstart);
   152     return (text - textstart);
   153 }
   153 }
   154 #endif
   154 #endif
   181         }
   181         }
   182         value *= radix;
   182         value *= radix;
   183         value += v;
   183         value += v;
   184         ++text;
   184         ++text;
   185     }
   185     }
   186     if (valuep) {
   186     if (valuep && text > textstart) {
   187         if (negative && value) {
   187         if (negative && value) {
   188             *valuep = -value;
   188             *valuep = -value;
   189         } else {
   189         } else {
   190             *valuep = value;
   190             *valuep = value;
   191         }
   191         }
   217         }
   217         }
   218         value *= radix;
   218         value *= radix;
   219         value += v;
   219         value += v;
   220         ++text;
   220         ++text;
   221     }
   221     }
   222     if (valuep) {
   222     if (valuep && text > textstart) {
   223         *valuep = value;
   223         *valuep = value;
   224     }
   224     }
   225     return (text - textstart);
   225     return (text - textstart);
   226 }
   226 }
   227 #endif
   227 #endif
   249             value += (double) lvalue / mult;
   249             value += (double) lvalue / mult;
   250             mult *= 10;
   250             mult *= 10;
   251             ++text;
   251             ++text;
   252         }
   252         }
   253     }
   253     }
   254     if (valuep) {
   254     if (valuep && text > textstart) {
   255         if (negative && value) {
   255         if (negative && value) {
   256             *valuep = -value;
   256             *valuep = -value;
   257         } else {
   257         } else {
   258             *valuep = value;
   258             *valuep = value;
   259         }
   259         }
  1023 int
  1023 int
  1024 SDL_vsscanf(const char *text, const char *fmt, va_list ap)
  1024 SDL_vsscanf(const char *text, const char *fmt, va_list ap)
  1025 {
  1025 {
  1026     int retval = 0;
  1026     int retval = 0;
  1027 
  1027 
       
  1028     if (!text || !*text) {
       
  1029         return -1;
       
  1030     }
       
  1031 
  1028     while (*fmt) {
  1032     while (*fmt) {
  1029         if (*fmt == ' ') {
  1033         if (*fmt == ' ') {
  1030             while (SDL_isspace((unsigned char) *text)) {
  1034             while (SDL_isspace((unsigned char) *text)) {
  1031                 ++text;
  1035                 ++text;
  1032             }
  1036             }
  1042                 DO_SHORT,
  1046                 DO_SHORT,
  1043                 DO_INT,
  1047                 DO_INT,
  1044                 DO_LONG,
  1048                 DO_LONG,
  1045                 DO_LONGLONG
  1049                 DO_LONGLONG
  1046             } inttype = DO_INT;
  1050             } inttype = DO_INT;
       
  1051             size_t advance;
  1047             SDL_bool suppress = SDL_FALSE;
  1052             SDL_bool suppress = SDL_FALSE;
  1048 
  1053 
  1049             ++fmt;
  1054             ++fmt;
  1050             if (*fmt == '%') {
  1055             if (*fmt == '%') {
  1051                 if (*text == '%') {
  1056                 if (*text == '%') {
  1129                             *valuep = value;
  1134                             *valuep = value;
  1130                             ++retval;
  1135                             ++retval;
  1131                         }
  1136                         }
  1132                     } else {
  1137                     } else {
  1133                         long value;
  1138                         long value;
  1134                         text += SDL_ScanLong(text, radix, &value);
  1139                         advance = SDL_ScanLong(text, radix, &value);
  1135                         if (!suppress) {
  1140                         text += advance;
       
  1141                         if (advance && !suppress) {
  1136                             switch (inttype) {
  1142                             switch (inttype) {
  1137                             case DO_SHORT:
  1143                             case DO_SHORT:
  1138                                 {
  1144                                 {
  1139                                     short *valuep = va_arg(ap, short *);
  1145                                     short *valuep = va_arg(ap, short *);
  1140                                     *valuep = (short) value;
  1146                                     *valuep = (short) value;
  1173                     }
  1179                     }
  1174                     /* Fall through to unsigned handling */
  1180                     /* Fall through to unsigned handling */
  1175                 case 'u':
  1181                 case 'u':
  1176                     if (inttype == DO_LONGLONG) {
  1182                     if (inttype == DO_LONGLONG) {
  1177                         Uint64 value;
  1183                         Uint64 value;
  1178                         text += SDL_ScanUnsignedLongLong(text, radix, &value);
  1184                         advance = SDL_ScanUnsignedLongLong(text, radix, &value);
  1179                         if (!suppress) {
  1185                         text += advance;
       
  1186                         if (advance && !suppress) {
  1180                             Uint64 *valuep = va_arg(ap, Uint64 *);
  1187                             Uint64 *valuep = va_arg(ap, Uint64 *);
  1181                             *valuep = value;
  1188                             *valuep = value;
  1182                             ++retval;
  1189                             ++retval;
  1183                         }
  1190                         }
  1184                     } else {
  1191                     } else {
  1185                         unsigned long value;
  1192                         unsigned long value;
  1186                         text += SDL_ScanUnsignedLong(text, radix, &value);
  1193                         advance = SDL_ScanUnsignedLong(text, radix, &value);
  1187                         if (!suppress) {
  1194                         text += advance;
       
  1195                         if (advance && !suppress) {
  1188                             switch (inttype) {
  1196                             switch (inttype) {
  1189                             case DO_SHORT:
  1197                             case DO_SHORT:
  1190                                 {
  1198                                 {
  1191                                     short *valuep = va_arg(ap, short *);
  1199                                     short *valuep = va_arg(ap, short *);
  1192                                     *valuep = (short) value;
  1200                                     *valuep = (short) value;
  1214                     done = SDL_TRUE;
  1222                     done = SDL_TRUE;
  1215                     break;
  1223                     break;
  1216                 case 'p':
  1224                 case 'p':
  1217                     {
  1225                     {
  1218                         uintptr_t value;
  1226                         uintptr_t value;
  1219                         text += SDL_ScanUintPtrT(text, 16, &value);
  1227                         advance = SDL_ScanUintPtrT(text, 16, &value);
  1220                         if (!suppress) {
  1228                         text += advance;
       
  1229                         if (advance && !suppress) {
  1221                             void **valuep = va_arg(ap, void **);
  1230                             void **valuep = va_arg(ap, void **);
  1222                             *valuep = (void *) value;
  1231                             *valuep = (void *) value;
  1223                             ++retval;
  1232                             ++retval;
  1224                         }
  1233                         }
  1225                     }
  1234                     }
  1226                     done = SDL_TRUE;
  1235                     done = SDL_TRUE;
  1227                     break;
  1236                     break;
  1228                 case 'f':
  1237                 case 'f':
  1229                     {
  1238                     {
  1230                         double value;
  1239                         double value;
  1231                         text += SDL_ScanFloat(text, &value);
  1240                         advance = SDL_ScanFloat(text, &value);
  1232                         if (!suppress) {
  1241                         text += advance;
       
  1242                         if (advance && !suppress) {
  1233                             float *valuep = va_arg(ap, float *);
  1243                             float *valuep = va_arg(ap, float *);
  1234                             *valuep = (float) value;
  1244                             *valuep = (float) value;
  1235                             ++retval;
  1245                             ++retval;
  1236                         }
  1246                         }
  1237                     }
  1247                     }