Mercurial > sdl-ios-xcode
comparison src/stdlib/SDL_string.c @ 3916:16f7767f9580 SDL-1.2
Force chars to unsigned chars in SDL_string.c, so platforms that expect
these to not be negative, when not EOF, work.
Fixes Bugzilla #338.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 15 Feb 2007 11:06:22 +0000 |
parents | 887c3600826b |
children | d3c1161652d5 |
comparison
equal
deleted
inserted
replaced
3915:89b0f3d12fe2 | 3916:16f7767f9580 |
---|---|
43 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { | 43 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { |
44 text += 2; | 44 text += 2; |
45 } | 45 } |
46 for ( ; ; ) { | 46 for ( ; ; ) { |
47 int v; | 47 int v; |
48 if ( SDL_isdigit(*text) ) { | 48 if ( SDL_isdigit((unsigned char) *text) ) { |
49 v = *text - '0'; | 49 v = *text - '0'; |
50 } else if ( radix == 16 && SDL_isupperhex(*text) ) { | 50 } else if ( radix == 16 && SDL_isupperhex(*text) ) { |
51 v = 10 + (*text - 'A'); | 51 v = 10 + (*text - 'A'); |
52 } else if ( radix == 16 && SDL_islowerhex(*text) ) { | 52 } else if ( radix == 16 && SDL_islowerhex(*text) ) { |
53 v = 10 + (*text - 'a'); | 53 v = 10 + (*text - 'a'); |
78 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { | 78 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { |
79 text += 2; | 79 text += 2; |
80 } | 80 } |
81 for ( ; ; ) { | 81 for ( ; ; ) { |
82 int v; | 82 int v; |
83 if ( SDL_isdigit(*text) ) { | 83 if ( SDL_isdigit((unsigned char) *text) ) { |
84 v = *text - '0'; | 84 v = *text - '0'; |
85 } else if ( radix == 16 && SDL_isupperhex(*text) ) { | 85 } else if ( radix == 16 && SDL_isupperhex(*text) ) { |
86 v = 10 + (*text - 'A'); | 86 v = 10 + (*text - 'A'); |
87 } else if ( radix == 16 && SDL_islowerhex(*text) ) { | 87 } else if ( radix == 16 && SDL_islowerhex(*text) ) { |
88 v = 10 + (*text - 'a'); | 88 v = 10 + (*text - 'a'); |
109 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { | 109 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { |
110 text += 2; | 110 text += 2; |
111 } | 111 } |
112 for ( ; ; ) { | 112 for ( ; ; ) { |
113 int v; | 113 int v; |
114 if ( SDL_isdigit(*text) ) { | 114 if ( SDL_isdigit((unsigned char) *text) ) { |
115 v = *text - '0'; | 115 v = *text - '0'; |
116 } else if ( radix == 16 && SDL_isupperhex(*text) ) { | 116 } else if ( radix == 16 && SDL_isupperhex(*text) ) { |
117 v = 10 + (*text - 'A'); | 117 v = 10 + (*text - 'A'); |
118 } else if ( radix == 16 && SDL_islowerhex(*text) ) { | 118 } else if ( radix == 16 && SDL_islowerhex(*text) ) { |
119 v = 10 + (*text - 'a'); | 119 v = 10 + (*text - 'a'); |
146 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { | 146 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { |
147 text += 2; | 147 text += 2; |
148 } | 148 } |
149 for ( ; ; ) { | 149 for ( ; ; ) { |
150 int v; | 150 int v; |
151 if ( SDL_isdigit(*text) ) { | 151 if ( SDL_isdigit((unsigned char) *text) ) { |
152 v = *text - '0'; | 152 v = *text - '0'; |
153 } else if ( radix == 16 && SDL_isupperhex(*text) ) { | 153 } else if ( radix == 16 && SDL_isupperhex(*text) ) { |
154 v = 10 + (*text - 'A'); | 154 v = 10 + (*text - 'A'); |
155 } else if ( radix == 16 && SDL_islowerhex(*text) ) { | 155 } else if ( radix == 16 && SDL_islowerhex(*text) ) { |
156 v = 10 + (*text - 'a'); | 156 v = 10 + (*text - 'a'); |
181 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { | 181 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { |
182 text += 2; | 182 text += 2; |
183 } | 183 } |
184 for ( ; ; ) { | 184 for ( ; ; ) { |
185 int v; | 185 int v; |
186 if ( SDL_isdigit(*text) ) { | 186 if ( SDL_isdigit((unsigned char) *text) ) { |
187 v = *text - '0'; | 187 v = *text - '0'; |
188 } else if ( radix == 16 && SDL_isupperhex(*text) ) { | 188 } else if ( radix == 16 && SDL_isupperhex(*text) ) { |
189 v = 10 + (*text - 'A'); | 189 v = 10 + (*text - 'A'); |
190 } else if ( radix == 16 && SDL_islowerhex(*text) ) { | 190 } else if ( radix == 16 && SDL_islowerhex(*text) ) { |
191 v = 10 + (*text - 'a'); | 191 v = 10 + (*text - 'a'); |
219 text += SDL_ScanUnsignedLong(text, 10, &lvalue); | 219 text += SDL_ScanUnsignedLong(text, 10, &lvalue); |
220 value += lvalue; | 220 value += lvalue; |
221 if ( *text == '.' ) { | 221 if ( *text == '.' ) { |
222 int mult = 10; | 222 int mult = 10; |
223 ++text; | 223 ++text; |
224 while ( SDL_isdigit(*text) ) { | 224 while ( SDL_isdigit((unsigned char) *text) ) { |
225 lvalue = *text - '0'; | 225 lvalue = *text - '0'; |
226 value += (double)lvalue / mult; | 226 value += (double)lvalue / mult; |
227 mult *= 10; | 227 mult *= 10; |
228 ++text; | 228 ++text; |
229 } | 229 } |
381 #ifndef HAVE__STRUPR | 381 #ifndef HAVE__STRUPR |
382 char *SDL_strupr(char *string) | 382 char *SDL_strupr(char *string) |
383 { | 383 { |
384 char *bufp = string; | 384 char *bufp = string; |
385 while ( *bufp ) { | 385 while ( *bufp ) { |
386 *bufp = SDL_toupper(*bufp); | 386 *bufp = SDL_toupper((unsigned char) *bufp); |
387 ++bufp; | 387 ++bufp; |
388 } | 388 } |
389 return string; | 389 return string; |
390 } | 390 } |
391 #endif | 391 #endif |
393 #ifndef HAVE__STRLWR | 393 #ifndef HAVE__STRLWR |
394 char *SDL_strlwr(char *string) | 394 char *SDL_strlwr(char *string) |
395 { | 395 { |
396 char *bufp = string; | 396 char *bufp = string; |
397 while ( *bufp ) { | 397 while ( *bufp ) { |
398 *bufp = SDL_tolower(*bufp); | 398 *bufp = SDL_tolower((unsigned char) *bufp); |
399 ++bufp; | 399 ++bufp; |
400 } | 400 } |
401 return string; | 401 return string; |
402 } | 402 } |
403 #endif | 403 #endif |
697 int SDL_strcasecmp(const char *str1, const char *str2) | 697 int SDL_strcasecmp(const char *str1, const char *str2) |
698 { | 698 { |
699 char a = 0; | 699 char a = 0; |
700 char b = 0; | 700 char b = 0; |
701 while ( *str1 && *str2 ) { | 701 while ( *str1 && *str2 ) { |
702 a = SDL_tolower(*str1); | 702 a = SDL_tolower((unsigned char) *str1); |
703 b = SDL_tolower(*str2); | 703 b = SDL_tolower((unsigned char) *str2); |
704 if ( a != b ) | 704 if ( a != b ) |
705 break; | 705 break; |
706 ++str1; | 706 ++str1; |
707 ++str2; | 707 ++str2; |
708 } | 708 } |
714 int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) | 714 int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) |
715 { | 715 { |
716 char a = 0; | 716 char a = 0; |
717 char b = 0; | 717 char b = 0; |
718 while ( *str1 && *str2 && maxlen ) { | 718 while ( *str1 && *str2 && maxlen ) { |
719 a = SDL_tolower(*str1); | 719 a = SDL_tolower((unsigned char) *str1); |
720 b = SDL_tolower(*str2); | 720 b = SDL_tolower((unsigned char) *str2); |
721 if ( a != b ) | 721 if ( a != b ) |
722 break; | 722 break; |
723 ++str1; | 723 ++str1; |
724 ++str2; | 724 ++str2; |
725 --maxlen; | 725 --maxlen; |
735 int retval = 0; | 735 int retval = 0; |
736 | 736 |
737 va_start(ap, fmt); | 737 va_start(ap, fmt); |
738 while ( *fmt ) { | 738 while ( *fmt ) { |
739 if ( *fmt == ' ' ) { | 739 if ( *fmt == ' ' ) { |
740 while ( SDL_isspace(*text) ) { | 740 while ( SDL_isspace((unsigned char) *text) ) { |
741 ++text; | 741 ++text; |
742 } | 742 } |
743 ++fmt; | 743 ++fmt; |
744 continue; | 744 continue; |
745 } | 745 } |
786 ++retval; | 786 ++retval; |
787 } | 787 } |
788 continue; | 788 continue; |
789 } | 789 } |
790 | 790 |
791 while ( SDL_isspace(*text) ) { | 791 while ( SDL_isspace((unsigned char) *text) ) { |
792 ++text; | 792 ++text; |
793 } | 793 } |
794 | 794 |
795 /* FIXME: implement more of the format specifiers */ | 795 /* FIXME: implement more of the format specifiers */ |
796 while (!done) { | 796 while (!done) { |
819 int index = 0; | 819 int index = 0; |
820 if ( text[index] == '-' ) { | 820 if ( text[index] == '-' ) { |
821 ++index; | 821 ++index; |
822 } | 822 } |
823 if ( text[index] == '0' ) { | 823 if ( text[index] == '0' ) { |
824 if ( SDL_tolower(text[index+1]) == 'x' ) { | 824 if ( SDL_tolower((unsigned char) text[index+1]) == 'x' ) { |
825 radix = 16; | 825 radix = 16; |
826 } else { | 826 } else { |
827 radix = 8; | 827 radix = 8; |
828 } | 828 } |
829 } | 829 } |
948 } | 948 } |
949 done = SDL_TRUE; | 949 done = SDL_TRUE; |
950 break; | 950 break; |
951 case 's': | 951 case 's': |
952 if ( suppress ) { | 952 if ( suppress ) { |
953 while ( !SDL_isspace(*text) ) { | 953 while ( !SDL_isspace((unsigned char) *text) ) { |
954 ++text; | 954 ++text; |
955 if ( count ) { | 955 if ( count ) { |
956 if ( --count == 0 ) { | 956 if ( --count == 0 ) { |
957 break; | 957 break; |
958 } | 958 } |
959 } | 959 } |
960 } | 960 } |
961 } else { | 961 } else { |
962 char *valuep = va_arg(ap, char*); | 962 char *valuep = va_arg(ap, char*); |
963 while ( !SDL_isspace(*text) ) { | 963 while ( !SDL_isspace((unsigned char) *text) ) { |
964 *valuep++ = *text++; | 964 *valuep++ = *text++; |
965 if ( count ) { | 965 if ( count ) { |
966 if ( --count == 0 ) { | 966 if ( --count == 0 ) { |
967 break; | 967 break; |
968 } | 968 } |