Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 2 | Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, |
| 3 | Amsterdam, The Netherlands. |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
| 25 | /* strop module */ |
| 26 | |
| 27 | #include "allobjects.h" |
| 28 | #include "modsupport.h" |
| 29 | |
Guido van Rossum | d05eb8b | 1993-07-08 11:12:36 +0000 | [diff] [blame] | 30 | #include <ctype.h> |
Guido van Rossum | e22e644 | 1993-07-09 10:51:31 +0000 | [diff] [blame] | 31 | /* XXX This file assumes that the <ctype.h> is*() functions |
| 32 | XXX are defined for all 8-bit characters! */ |
Guido van Rossum | d05eb8b | 1993-07-08 11:12:36 +0000 | [diff] [blame] | 33 | |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 34 | |
| 35 | static object * |
| 36 | strop_split(self, args) |
| 37 | object *self; /* Not used */ |
| 38 | object *args; |
| 39 | { |
Guido van Rossum | 572d2d9 | 1993-11-05 10:14:49 +0000 | [diff] [blame] | 40 | int len, i, j, err; |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 41 | char *s; |
| 42 | char c; |
| 43 | object *list, *item; |
| 44 | |
| 45 | if (!getargs(args, "s#", &s, &len)) |
| 46 | return NULL; |
| 47 | list = newlistobject(0); |
| 48 | if (list == NULL) |
| 49 | return NULL; |
| 50 | |
| 51 | i = 0; |
| 52 | while (i < len) { |
| 53 | while (i < len && |
Guido van Rossum | d05eb8b | 1993-07-08 11:12:36 +0000 | [diff] [blame] | 54 | ((c = s[i]), isspace(c))) { |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 55 | i = i+1; |
| 56 | } |
| 57 | j = i; |
| 58 | while (i < len && |
Guido van Rossum | d05eb8b | 1993-07-08 11:12:36 +0000 | [diff] [blame] | 59 | !((c = s[i]), isspace(c))) { |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 60 | i = i+1; |
| 61 | } |
| 62 | if (j < i) { |
| 63 | item = newsizedstringobject(s+j, (int)(i-j)); |
Guido van Rossum | 572d2d9 | 1993-11-05 10:14:49 +0000 | [diff] [blame] | 64 | if (item == NULL) { |
| 65 | DECREF(list); |
| 66 | return NULL; |
| 67 | } |
| 68 | err = addlistitem(list, item); |
| 69 | DECREF(item); |
| 70 | if (err < 0) { |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 71 | DECREF(list); |
| 72 | return NULL; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return list; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | static object * |
| 82 | strop_splitfields(self, args) |
| 83 | object *self; /* Not used */ |
| 84 | object *args; |
| 85 | { |
Guido van Rossum | 572d2d9 | 1993-11-05 10:14:49 +0000 | [diff] [blame] | 86 | int len, n, i, j, err; |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 87 | char *s, *sub; |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 88 | object *list, *item; |
| 89 | |
| 90 | if (!getargs(args, "(s#s#)", &s, &len, &sub, &n)) |
| 91 | return NULL; |
| 92 | if (n == 0) { |
| 93 | err_setstr(ValueError, "empty separator"); |
| 94 | return NULL; |
| 95 | } |
| 96 | |
| 97 | list = newlistobject(0); |
| 98 | if (list == NULL) |
| 99 | return NULL; |
| 100 | |
| 101 | i = j = 0; |
| 102 | while (i+n <= len) { |
| 103 | if (s[i] == sub[0] && (n == 1 || strncmp(s+i, sub, n) == 0)) { |
| 104 | item = newsizedstringobject(s+j, (int)(i-j)); |
Guido van Rossum | 572d2d9 | 1993-11-05 10:14:49 +0000 | [diff] [blame] | 105 | if (item == NULL) |
| 106 | goto fail; |
| 107 | err = addlistitem(list, item); |
| 108 | DECREF(item); |
| 109 | if (err < 0) |
| 110 | goto fail; |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 111 | i = j = i + n; |
| 112 | } |
| 113 | else |
| 114 | i++; |
| 115 | } |
| 116 | item = newsizedstringobject(s+j, (int)(len-j)); |
Guido van Rossum | 572d2d9 | 1993-11-05 10:14:49 +0000 | [diff] [blame] | 117 | if (item == NULL) |
| 118 | goto fail; |
| 119 | err = addlistitem(list, item); |
| 120 | DECREF(item); |
| 121 | if (err < 0) |
| 122 | goto fail; |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 123 | |
| 124 | return list; |
Guido van Rossum | 572d2d9 | 1993-11-05 10:14:49 +0000 | [diff] [blame] | 125 | |
| 126 | fail: |
| 127 | DECREF(list); |
| 128 | return NULL; |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | |
| 132 | static object * |
Guido van Rossum | c89705d | 1992-11-26 08:54:07 +0000 | [diff] [blame] | 133 | strop_joinfields(self, args) |
| 134 | object *self; /* Not used */ |
| 135 | object *args; |
| 136 | { |
| 137 | object *seq, *item, *res; |
| 138 | object * (*getitem) FPROTO((object *, int)); |
| 139 | char *sep, *p; |
| 140 | int seplen, seqlen, reslen, itemlen, i; |
| 141 | |
| 142 | if (!getargs(args, "(Os#)", &seq, &sep, &seplen)) |
| 143 | return NULL; |
| 144 | if (is_listobject(seq)) { |
| 145 | getitem = getlistitem; |
| 146 | seqlen = getlistsize(seq); |
| 147 | } |
| 148 | else if (is_tupleobject(seq)) { |
| 149 | getitem = gettupleitem; |
| 150 | seqlen = gettuplesize(seq); |
| 151 | } |
| 152 | else { |
| 153 | err_setstr(TypeError, "first argument must be list/tuple"); |
| 154 | return NULL; |
| 155 | } |
| 156 | reslen = 0; |
| 157 | for (i = 0; i < seqlen; i++) { |
| 158 | item = getitem(seq, i); |
| 159 | if (!is_stringobject(item)) { |
| 160 | err_setstr(TypeError, |
| 161 | "first argument must be list/tuple of strings"); |
| 162 | return NULL; |
| 163 | } |
| 164 | if (i > 0) |
| 165 | reslen = reslen + seplen; |
| 166 | reslen = reslen + getstringsize(item); |
| 167 | } |
| 168 | if (seqlen == 1) { |
| 169 | /* Optimization if there's only one item */ |
| 170 | item = getitem(seq, 0); |
| 171 | INCREF(item); |
| 172 | return item; |
| 173 | } |
| 174 | res = newsizedstringobject((char *)NULL, reslen); |
| 175 | if (res == NULL) |
| 176 | return NULL; |
| 177 | p = getstringvalue(res); |
| 178 | for (i = 0; i < seqlen; i++) { |
| 179 | item = getitem(seq, i); |
| 180 | if (i > 0) { |
| 181 | memcpy(p, sep, seplen); |
| 182 | p += seplen; |
| 183 | } |
| 184 | itemlen = getstringsize(item); |
| 185 | memcpy(p, getstringvalue(item), itemlen); |
| 186 | p += itemlen; |
| 187 | } |
| 188 | if (p != getstringvalue(res) + reslen) { |
| 189 | err_setstr(SystemError, "strop.joinfields: assertion failed"); |
| 190 | return NULL; |
| 191 | } |
| 192 | return res; |
| 193 | } |
| 194 | |
| 195 | |
| 196 | static object * |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 197 | strop_index(self, args) |
| 198 | object *self; /* Not used */ |
| 199 | object *args; |
| 200 | { |
| 201 | char *s, *sub; |
| 202 | int len, n, i; |
| 203 | |
| 204 | if (getargs(args, "(s#s#i)", &s, &len, &sub, &n, &i)) { |
Guido van Rossum | ee9012f | 1993-10-26 15:23:55 +0000 | [diff] [blame] | 205 | if (i < 0) |
| 206 | i += len; |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 207 | if (i < 0 || i+n > len) { |
| 208 | err_setstr(ValueError, "start offset out of range"); |
| 209 | return NULL; |
| 210 | } |
| 211 | } |
| 212 | else { |
| 213 | err_clear(); |
| 214 | if (!getargs(args, "(s#s#)", &s, &len, &sub, &n)) |
| 215 | return NULL; |
| 216 | i = 0; |
| 217 | } |
| 218 | |
| 219 | if (n == 0) |
| 220 | return newintobject((long)i); |
| 221 | |
| 222 | len -= n; |
Guido van Rossum | ee9012f | 1993-10-26 15:23:55 +0000 | [diff] [blame] | 223 | for (; i <= len; ++i) |
| 224 | if (s[i] == sub[0] && |
| 225 | (n == 1 || strncmp(&s[i+1], &sub[1], n-1) == 0)) |
| 226 | return newintobject((long)i); |
| 227 | |
| 228 | err_setstr(ValueError, "substring not found"); |
| 229 | return NULL; |
| 230 | } |
| 231 | |
| 232 | |
| 233 | static object * |
| 234 | strop_rindex(self, args) |
| 235 | object *self; /* Not used */ |
| 236 | object *args; |
| 237 | { |
| 238 | char *s, *sub; |
| 239 | int len, n, i; |
| 240 | |
| 241 | if (getargs(args, "(s#s#i)", &s, &len, &sub, &n, &i)) { |
| 242 | if (i < 0) |
| 243 | i += len; |
| 244 | if (i < 0 || i+n > len) { |
| 245 | err_setstr(ValueError, "start offset out of range"); |
| 246 | return NULL; |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 247 | } |
| 248 | } |
Guido van Rossum | ee9012f | 1993-10-26 15:23:55 +0000 | [diff] [blame] | 249 | else { |
| 250 | err_clear(); |
| 251 | if (!getargs(args, "(s#s#)", &s, &len, &sub, &n)) |
| 252 | return NULL; |
| 253 | i = len; |
| 254 | } |
| 255 | |
| 256 | if (n == 0) |
| 257 | return newintobject((long)i); |
| 258 | |
| 259 | for (i -= n; i >= 0; --i) |
| 260 | if (s[i] == sub[0] && |
| 261 | (n == 1 || strncmp(&s[i+1], &sub[1], n-1) == 0)) |
| 262 | return newintobject((long)i); |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 263 | |
| 264 | err_setstr(ValueError, "substring not found"); |
| 265 | return NULL; |
| 266 | } |
| 267 | |
| 268 | |
| 269 | static object * |
| 270 | strop_strip(self, args) |
| 271 | object *self; /* Not used */ |
| 272 | object *args; |
| 273 | { |
| 274 | char *s; |
| 275 | int len, i, j; |
| 276 | char c; |
| 277 | |
| 278 | if (!getargs(args, "s#", &s, &len)) |
| 279 | return NULL; |
| 280 | |
| 281 | i = 0; |
Guido van Rossum | d05eb8b | 1993-07-08 11:12:36 +0000 | [diff] [blame] | 282 | while (i < len && ((c = s[i]), isspace(c))) { |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 283 | i++; |
| 284 | } |
| 285 | |
| 286 | j = len; |
| 287 | do { |
| 288 | j--; |
Guido van Rossum | d05eb8b | 1993-07-08 11:12:36 +0000 | [diff] [blame] | 289 | } while (j >= i && ((c = s[j]), isspace(c))); |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 290 | j++; |
| 291 | |
| 292 | if (i == 0 && j == len) { |
| 293 | INCREF(args); |
| 294 | return args; |
| 295 | } |
| 296 | else |
| 297 | return newsizedstringobject(s+i, j-i); |
| 298 | } |
| 299 | |
| 300 | |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 301 | static object * |
| 302 | strop_lower(self, args) |
| 303 | object *self; /* Not used */ |
| 304 | object *args; |
| 305 | { |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 306 | char *s, *s_new; |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 307 | int i, n; |
| 308 | object *new; |
| 309 | int changed; |
| 310 | |
| 311 | if (!getargs(args, "s#", &s, &n)) |
| 312 | return NULL; |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 313 | new = newsizedstringobject(NULL, n); |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 314 | if (new == NULL) |
| 315 | return NULL; |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 316 | s_new = getstringvalue(new); |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 317 | changed = 0; |
| 318 | for (i = 0; i < n; i++) { |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 319 | char c = *s++; |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 320 | if (isupper(c)) { |
| 321 | changed = 1; |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 322 | *s_new = tolower(c); |
| 323 | } else |
| 324 | *s_new = c; |
| 325 | s_new++; |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 326 | } |
| 327 | if (!changed) { |
| 328 | DECREF(new); |
| 329 | INCREF(args); |
| 330 | return args; |
| 331 | } |
| 332 | return new; |
| 333 | } |
| 334 | |
| 335 | |
| 336 | static object * |
| 337 | strop_upper(self, args) |
| 338 | object *self; /* Not used */ |
| 339 | object *args; |
| 340 | { |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 341 | char *s, *s_new; |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 342 | int i, n; |
| 343 | object *new; |
| 344 | int changed; |
| 345 | |
| 346 | if (!getargs(args, "s#", &s, &n)) |
| 347 | return NULL; |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 348 | new = newsizedstringobject(NULL, n); |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 349 | if (new == NULL) |
| 350 | return NULL; |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 351 | s_new = getstringvalue(new); |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 352 | changed = 0; |
| 353 | for (i = 0; i < n; i++) { |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 354 | char c = *s++; |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 355 | if (islower(c)) { |
| 356 | changed = 1; |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 357 | *s_new = toupper(c); |
| 358 | } else |
| 359 | *s_new = c; |
| 360 | s_new++; |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 361 | } |
| 362 | if (!changed) { |
| 363 | DECREF(new); |
| 364 | INCREF(args); |
| 365 | return args; |
| 366 | } |
| 367 | return new; |
| 368 | } |
| 369 | |
| 370 | |
| 371 | static object * |
| 372 | strop_swapcase(self, args) |
| 373 | object *self; /* Not used */ |
| 374 | object *args; |
| 375 | { |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 376 | char *s, *s_new; |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 377 | int i, n; |
| 378 | object *new; |
| 379 | int changed; |
| 380 | |
| 381 | if (!getargs(args, "s#", &s, &n)) |
| 382 | return NULL; |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 383 | new = newsizedstringobject(NULL, n); |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 384 | if (new == NULL) |
| 385 | return NULL; |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 386 | s_new = getstringvalue(new); |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 387 | changed = 0; |
| 388 | for (i = 0; i < n; i++) { |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 389 | char c = *s++; |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 390 | if (islower(c)) { |
| 391 | changed = 1; |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 392 | *s_new = toupper(c); |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 393 | } |
| 394 | else if (isupper(c)) { |
| 395 | changed = 1; |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 396 | *s_new = tolower(c); |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 397 | } |
Sjoerd Mullender | 3bb8a05 | 1993-10-22 12:04:32 +0000 | [diff] [blame] | 398 | else |
| 399 | *s_new = c; |
| 400 | s_new++; |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 401 | } |
| 402 | if (!changed) { |
| 403 | DECREF(new); |
| 404 | INCREF(args); |
| 405 | return args; |
| 406 | } |
| 407 | return new; |
| 408 | } |
| 409 | |
| 410 | |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 411 | /* List of functions defined in the module */ |
| 412 | |
| 413 | static struct methodlist strop_methods[] = { |
| 414 | {"index", strop_index}, |
Guido van Rossum | c89705d | 1992-11-26 08:54:07 +0000 | [diff] [blame] | 415 | {"joinfields", strop_joinfields}, |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 416 | {"lower", strop_lower}, |
Guido van Rossum | ee9012f | 1993-10-26 15:23:55 +0000 | [diff] [blame] | 417 | {"rindex", strop_rindex}, |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 418 | {"split", strop_split}, |
| 419 | {"splitfields", strop_splitfields}, |
| 420 | {"strip", strop_strip}, |
Guido van Rossum | 5c85062 | 1992-09-11 23:55:51 +0000 | [diff] [blame] | 421 | {"swapcase", strop_swapcase}, |
| 422 | {"upper", strop_upper}, |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 423 | {NULL, NULL} /* sentinel */ |
| 424 | }; |
| 425 | |
| 426 | |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 427 | void |
| 428 | initstrop() |
| 429 | { |
Guido van Rossum | d05eb8b | 1993-07-08 11:12:36 +0000 | [diff] [blame] | 430 | object *m, *d, *s; |
| 431 | char buf[256]; |
| 432 | int c, n; |
| 433 | m = initmodule("strop", strop_methods); |
| 434 | d = getmoduledict(m); |
Guido van Rossum | e22e644 | 1993-07-09 10:51:31 +0000 | [diff] [blame] | 435 | |
| 436 | /* Create 'whitespace' object */ |
Guido van Rossum | d05eb8b | 1993-07-08 11:12:36 +0000 | [diff] [blame] | 437 | n = 0; |
| 438 | for (c = 1; c < 256; c++) { |
| 439 | if (isspace(c)) |
| 440 | buf[n++] = c; |
| 441 | } |
Sjoerd Mullender | d96ec44 | 1993-09-14 08:37:39 +0000 | [diff] [blame] | 442 | s = newsizedstringobject(buf, n); |
Guido van Rossum | e22e644 | 1993-07-09 10:51:31 +0000 | [diff] [blame] | 443 | if (s) { |
Guido van Rossum | e22e644 | 1993-07-09 10:51:31 +0000 | [diff] [blame] | 444 | dictinsert(d, "whitespace", s); |
| 445 | DECREF(s); |
| 446 | } |
| 447 | /* Create 'lowercase' object */ |
| 448 | n = 0; |
| 449 | for (c = 1; c < 256; c++) { |
| 450 | if (islower(c)) |
| 451 | buf[n++] = c; |
| 452 | } |
Guido van Rossum | d05eb8b | 1993-07-08 11:12:36 +0000 | [diff] [blame] | 453 | s = newsizedstringobject(buf, n); |
Guido van Rossum | e22e644 | 1993-07-09 10:51:31 +0000 | [diff] [blame] | 454 | if (s) { |
| 455 | dictinsert(d, "lowercase", s); |
| 456 | DECREF(s); |
| 457 | } |
| 458 | |
| 459 | /* Create 'uppercase' object */ |
| 460 | n = 0; |
| 461 | for (c = 1; c < 256; c++) { |
| 462 | if (isupper(c)) |
| 463 | buf[n++] = c; |
| 464 | } |
| 465 | s = newsizedstringobject(buf, n); |
| 466 | if (s) { |
| 467 | dictinsert(d, "uppercase", s); |
| 468 | DECREF(s); |
| 469 | } |
| 470 | |
| 471 | if (err_occurred()) |
| 472 | fatal("can't initialize module strop"); |
Guido van Rossum | e270b43 | 1992-09-03 20:21:07 +0000 | [diff] [blame] | 473 | } |