comparison src/stdlib/SDL_string.c @ 2092:8e761d6af583

Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 15 Feb 2007 11:14:24 +0000
parents c773b0c0ac89
children 4794e6f90feb
comparison
equal deleted inserted replaced
2091:b8bee470f737 2092:8e761d6af583
44 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { 44 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
45 text += 2; 45 text += 2;
46 } 46 }
47 for (;;) { 47 for (;;) {
48 int v; 48 int v;
49 if (SDL_isdigit(*text)) { 49 if (SDL_isdigit((unsigned char) *text)) {
50 v = *text - '0'; 50 v = *text - '0';
51 } else if (radix == 16 && SDL_isupperhex(*text)) { 51 } else if (radix == 16 && SDL_isupperhex(*text)) {
52 v = 10 + (*text - 'A'); 52 v = 10 + (*text - 'A');
53 } else if (radix == 16 && SDL_islowerhex(*text)) { 53 } else if (radix == 16 && SDL_islowerhex(*text)) {
54 v = 10 + (*text - 'a'); 54 v = 10 + (*text - 'a');
80 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { 80 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
81 text += 2; 81 text += 2;
82 } 82 }
83 for (;;) { 83 for (;;) {
84 int v; 84 int v;
85 if (SDL_isdigit(*text)) { 85 if (SDL_isdigit((unsigned char) *text)) {
86 v = *text - '0'; 86 v = *text - '0';
87 } else if (radix == 16 && SDL_isupperhex(*text)) { 87 } else if (radix == 16 && SDL_isupperhex(*text)) {
88 v = 10 + (*text - 'A'); 88 v = 10 + (*text - 'A');
89 } else if (radix == 16 && SDL_islowerhex(*text)) { 89 } else if (radix == 16 && SDL_islowerhex(*text)) {
90 v = 10 + (*text - 'a'); 90 v = 10 + (*text - 'a');
112 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { 112 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
113 text += 2; 113 text += 2;
114 } 114 }
115 for (;;) { 115 for (;;) {
116 int v; 116 int v;
117 if (SDL_isdigit(*text)) { 117 if (SDL_isdigit((unsigned char) *text)) {
118 v = *text - '0'; 118 v = *text - '0';
119 } else if (radix == 16 && SDL_isupperhex(*text)) { 119 } else if (radix == 16 && SDL_isupperhex(*text)) {
120 v = 10 + (*text - 'A'); 120 v = 10 + (*text - 'A');
121 } else if (radix == 16 && SDL_islowerhex(*text)) { 121 } else if (radix == 16 && SDL_islowerhex(*text)) {
122 v = 10 + (*text - 'a'); 122 v = 10 + (*text - 'a');
150 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { 150 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
151 text += 2; 151 text += 2;
152 } 152 }
153 for (;;) { 153 for (;;) {
154 int v; 154 int v;
155 if (SDL_isdigit(*text)) { 155 if (SDL_isdigit((unsigned char) *text)) {
156 v = *text - '0'; 156 v = *text - '0';
157 } else if (radix == 16 && SDL_isupperhex(*text)) { 157 } else if (radix == 16 && SDL_isupperhex(*text)) {
158 v = 10 + (*text - 'A'); 158 v = 10 + (*text - 'A');
159 } else if (radix == 16 && SDL_islowerhex(*text)) { 159 } else if (radix == 16 && SDL_islowerhex(*text)) {
160 v = 10 + (*text - 'a'); 160 v = 10 + (*text - 'a');
186 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { 186 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
187 text += 2; 187 text += 2;
188 } 188 }
189 for (;;) { 189 for (;;) {
190 int v; 190 int v;
191 if (SDL_isdigit(*text)) { 191 if (SDL_isdigit((unsigned char) *text)) {
192 v = *text - '0'; 192 v = *text - '0';
193 } else if (radix == 16 && SDL_isupperhex(*text)) { 193 } else if (radix == 16 && SDL_isupperhex(*text)) {
194 v = 10 + (*text - 'A'); 194 v = 10 + (*text - 'A');
195 } else if (radix == 16 && SDL_islowerhex(*text)) { 195 } else if (radix == 16 && SDL_islowerhex(*text)) {
196 v = 10 + (*text - 'a'); 196 v = 10 + (*text - 'a');
225 text += SDL_ScanUnsignedLong(text, 10, &lvalue); 225 text += SDL_ScanUnsignedLong(text, 10, &lvalue);
226 value += lvalue; 226 value += lvalue;
227 if (*text == '.') { 227 if (*text == '.') {
228 int mult = 10; 228 int mult = 10;
229 ++text; 229 ++text;
230 while (SDL_isdigit(*text)) { 230 while (SDL_isdigit((unsigned char) *text)) {
231 lvalue = *text - '0'; 231 lvalue = *text - '0';
232 value += (double) lvalue / mult; 232 value += (double) lvalue / mult;
233 mult *= 10; 233 mult *= 10;
234 ++text; 234 ++text;
235 } 235 }
409 char * 409 char *
410 SDL_strupr(char *string) 410 SDL_strupr(char *string)
411 { 411 {
412 char *bufp = string; 412 char *bufp = string;
413 while (*bufp) { 413 while (*bufp) {
414 *bufp = SDL_toupper(*bufp); 414 *bufp = SDL_toupper((unsigned char) *bufp);
415 ++bufp; 415 ++bufp;
416 } 416 }
417 return string; 417 return string;
418 } 418 }
419 #endif 419 #endif
422 char * 422 char *
423 SDL_strlwr(char *string) 423 SDL_strlwr(char *string)
424 { 424 {
425 char *bufp = string; 425 char *bufp = string;
426 while (*bufp) { 426 while (*bufp) {
427 *bufp = SDL_tolower(*bufp); 427 *bufp = SDL_tolower((unsigned char) *bufp);
428 ++bufp; 428 ++bufp;
429 } 429 }
430 return string; 430 return string;
431 } 431 }
432 #endif 432 #endif
741 SDL_strcasecmp(const char *str1, const char *str2) 741 SDL_strcasecmp(const char *str1, const char *str2)
742 { 742 {
743 char a = 0; 743 char a = 0;
744 char b = 0; 744 char b = 0;
745 while (*str1 && *str2) { 745 while (*str1 && *str2) {
746 a = SDL_tolower(*str1); 746 a = SDL_tolower((unsigned char) *str1);
747 b = SDL_tolower(*str2); 747 b = SDL_tolower((unsigned char) *str2);
748 if (a != b) 748 if (a != b)
749 break; 749 break;
750 ++str1; 750 ++str1;
751 ++str2; 751 ++str2;
752 } 752 }
761 SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) 761 SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
762 { 762 {
763 char a = 0; 763 char a = 0;
764 char b = 0; 764 char b = 0;
765 while (*str1 && *str2 && maxlen) { 765 while (*str1 && *str2 && maxlen) {
766 a = SDL_tolower(*str1); 766 a = SDL_tolower((unsigned char) *str1);
767 b = SDL_tolower(*str2); 767 b = SDL_tolower((unsigned char) *str2);
768 if (a != b) 768 if (a != b)
769 break; 769 break;
770 ++str1; 770 ++str1;
771 ++str2; 771 ++str2;
772 --maxlen; 772 --maxlen;
785 int retval = 0; 785 int retval = 0;
786 786
787 va_start(ap, fmt); 787 va_start(ap, fmt);
788 while (*fmt) { 788 while (*fmt) {
789 if (*fmt == ' ') { 789 if (*fmt == ' ') {
790 while (SDL_isspace(*text)) { 790 while (SDL_isspace((unsigned char) *text)) {
791 ++text; 791 ++text;
792 } 792 }
793 ++fmt; 793 ++fmt;
794 continue; 794 continue;
795 } 795 }
837 ++retval; 837 ++retval;
838 } 838 }
839 continue; 839 continue;
840 } 840 }
841 841
842 while (SDL_isspace(*text)) { 842 while (SDL_isspace((unsigned char) *text)) {
843 ++text; 843 ++text;
844 } 844 }
845 845
846 /* FIXME: implement more of the format specifiers */ 846 /* FIXME: implement more of the format specifiers */
847 while (!done) { 847 while (!done) {
870 int index = 0; 870 int index = 0;
871 if (text[index] == '-') { 871 if (text[index] == '-') {
872 ++index; 872 ++index;
873 } 873 }
874 if (text[index] == '0') { 874 if (text[index] == '0') {
875 if (SDL_tolower(text[index + 1]) == 'x') { 875 if (SDL_tolower((unsigned char) text[index + 1]) == 'x') {
876 radix = 16; 876 radix = 16;
877 } else { 877 } else {
878 radix = 8; 878 radix = 8;
879 } 879 }
880 } 880 }
1003 } 1003 }
1004 done = SDL_TRUE; 1004 done = SDL_TRUE;
1005 break; 1005 break;
1006 case 's': 1006 case 's':
1007 if (suppress) { 1007 if (suppress) {
1008 while (!SDL_isspace(*text)) { 1008 while (!SDL_isspace((unsigned char) *text)) {
1009 ++text; 1009 ++text;
1010 if (count) { 1010 if (count) {
1011 if (--count == 0) { 1011 if (--count == 0) {
1012 break; 1012 break;
1013 } 1013 }
1014 } 1014 }
1015 } 1015 }
1016 } else { 1016 } else {
1017 char *valuep = va_arg(ap, char *); 1017 char *valuep = va_arg(ap, char *);
1018 while (!SDL_isspace(*text)) { 1018 while (!SDL_isspace((unsigned char) *text)) {
1019 *valuep++ = *text++; 1019 *valuep++ = *text++;
1020 if (count) { 1020 if (count) {
1021 if (--count == 0) { 1021 if (--count == 0) {
1022 break; 1022 break;
1023 } 1023 }