4 static char strop_module__doc__
[] =
5 "Common string manipulations, optimized for speed.\n\
7 Always use \"import string\" rather than referencing\n\
8 this module directly.";
15 #define INT_MAX 2147483647
19 /* XXX This file assumes that the <ctype.h> is*() functions
20 XXX are defined for all 8-bit characters! */
22 /* The lstrip(), rstrip() and strip() functions are implemented
23 in do_strip(), which uses an additional parameter to indicate what
24 type of strip should occur. */
32 split_whitespace(char *s
, int len
, int maxsplit
)
37 PyObject
*list
= PyList_New(0);
43 while (i
< len
&& isspace(Py_CHARMASK(s
[i
]))) {
47 while (i
< len
&& !isspace(Py_CHARMASK(s
[i
]))) {
51 item
= PyString_FromStringAndSize(s
+j
, (int)(i
-j
));
55 err
= PyList_Append(list
, item
);
61 while (i
< len
&& isspace(Py_CHARMASK(s
[i
]))) {
64 if (maxsplit
&& (countsplit
>= maxsplit
) && i
< len
) {
65 item
= PyString_FromStringAndSize(
70 err
= PyList_Append(list
, item
);
86 static char splitfields__doc__
[] =
87 "split(s [,sep [,maxsplit]]) -> list of strings\n\
88 splitfields(s [,sep [,maxsplit]]) -> list of strings\n\
90 Return a list of the words in the string s, using sep as the\n\
91 delimiter string. If maxsplit is nonzero, splits into at most\n\
92 maxsplit words. If sep is not specified, any whitespace string\n\
93 is a separator. Maxsplit defaults to 0.\n\
95 (split and splitfields are synonymous)";
98 strop_splitfields(PyObject
*self
, PyObject
*args
)
100 int len
, n
, i
, j
, err
;
101 int splitcount
, maxsplit
;
103 PyObject
*list
, *item
;
109 if (!PyArg_ParseTuple(args
, "t#|z#i:split", &s
, &len
, &sub
, &n
, &maxsplit
))
112 return split_whitespace(s
, len
, maxsplit
);
114 PyErr_SetString(PyExc_ValueError
, "empty separator");
118 list
= PyList_New(0);
124 if (s
[i
] == sub
[0] && (n
== 1 || memcmp(s
+i
, sub
, n
) == 0)) {
125 item
= PyString_FromStringAndSize(s
+j
, (int)(i
-j
));
128 err
= PyList_Append(list
, item
);
134 if (maxsplit
&& (splitcount
>= maxsplit
))
140 item
= PyString_FromStringAndSize(s
+j
, (int)(len
-j
));
143 err
= PyList_Append(list
, item
);
156 static char joinfields__doc__
[] =
157 "join(list [,sep]) -> string\n\
158 joinfields(list [,sep]) -> string\n\
160 Return a string composed of the words in list, with\n\
161 intervening occurrences of sep. Sep defaults to a single\n\
164 (join and joinfields are synonymous)";
167 strop_joinfields(PyObject
*self
, PyObject
*args
)
171 int seqlen
, seplen
= 0;
172 int i
, reslen
= 0, slen
= 0, sz
= 100;
173 PyObject
*res
= NULL
;
175 intargfunc getitemfunc
;
177 if (!PyArg_ParseTuple(args
, "O|t#:join", &seq
, &sep
, &seplen
))
184 seqlen
= PySequence_Size(seq
);
185 if (seqlen
< 0 && PyErr_Occurred())
189 /* Optimization if there's only one item */
190 PyObject
*item
= PySequence_GetItem(seq
, 0);
191 if (item
&& !PyString_Check(item
)) {
192 PyErr_SetString(PyExc_TypeError
,
193 "first argument must be sequence of strings");
200 if (!(res
= PyString_FromStringAndSize((char*)NULL
, sz
)))
202 p
= PyString_AsString(res
);
204 /* optimize for lists, since it's the most common case. all others
205 * (tuples and arbitrary sequences) just use the sequence abstract
208 if (PyList_Check(seq
)) {
209 for (i
= 0; i
< seqlen
; i
++) {
210 PyObject
*item
= PyList_GET_ITEM(seq
, i
);
211 if (!PyString_Check(item
)) {
212 PyErr_SetString(PyExc_TypeError
,
213 "first argument must be sequence of strings");
217 slen
= PyString_GET_SIZE(item
);
218 while (reslen
+ slen
+ seplen
>= sz
) {
219 if (_PyString_Resize(&res
, sz
* 2)) {
224 p
= PyString_AsString(res
) + reslen
;
227 memcpy(p
, sep
, seplen
);
231 memcpy(p
, PyString_AS_STRING(item
), slen
);
235 if (_PyString_Resize(&res
, reslen
)) {
242 if (seq
->ob_type
->tp_as_sequence
== NULL
||
243 (getitemfunc
= seq
->ob_type
->tp_as_sequence
->sq_item
) == NULL
)
245 PyErr_SetString(PyExc_TypeError
,
246 "first argument must be a sequence");
249 /* This is now type safe */
250 for (i
= 0; i
< seqlen
; i
++) {
251 PyObject
*item
= getitemfunc(seq
, i
);
252 if (!item
|| !PyString_Check(item
)) {
253 PyErr_SetString(PyExc_TypeError
,
254 "first argument must be sequence of strings");
259 slen
= PyString_GET_SIZE(item
);
260 while (reslen
+ slen
+ seplen
>= sz
) {
261 if (_PyString_Resize(&res
, sz
* 2)) {
267 p
= PyString_AsString(res
) + reslen
;
270 memcpy(p
, sep
, seplen
);
274 memcpy(p
, PyString_AS_STRING(item
), slen
);
279 if (_PyString_Resize(&res
, reslen
)) {
287 static char find__doc__
[] =
288 "find(s, sub [,start [,end]]) -> in\n\
290 Return the lowest index in s where substring sub is found,\n\
291 such that sub is contained within s[start,end]. Optional\n\
292 arguments start and end are interpreted as in slice notation.\n\
294 Return -1 on failure.";
297 strop_find(PyObject
*self
, PyObject
*args
)
300 int len
, n
, i
= 0, last
= INT_MAX
;
302 if (!PyArg_ParseTuple(args
, "t#t#|ii:find", &s
, &len
, &sub
, &n
, &i
, &last
))
316 if (n
== 0 && i
<= last
)
317 return PyInt_FromLong((long)i
);
320 for (; i
<= last
; ++i
)
321 if (s
[i
] == sub
[0] &&
322 (n
== 1 || memcmp(&s
[i
+1], &sub
[1], n
-1) == 0))
323 return PyInt_FromLong((long)i
);
325 return PyInt_FromLong(-1L);
329 static char rfind__doc__
[] =
330 "rfind(s, sub [,start [,end]]) -> int\n\
332 Return the highest index in s where substring sub is found,\n\
333 such that sub is contained within s[start,end]. Optional\n\
334 arguments start and end are interpreted as in slice notation.\n\
336 Return -1 on failure.";
339 strop_rfind(PyObject
*self
, PyObject
*args
)
343 int i
= 0, last
= INT_MAX
;
345 if (!PyArg_ParseTuple(args
, "t#t#|ii:rfind", &s
, &len
, &sub
, &n
, &i
, &last
))
359 if (n
== 0 && i
<= last
)
360 return PyInt_FromLong((long)last
);
362 for (j
= last
-n
; j
>= i
; --j
)
363 if (s
[j
] == sub
[0] &&
364 (n
== 1 || memcmp(&s
[j
+1], &sub
[1], n
-1) == 0))
365 return PyInt_FromLong((long)j
);
367 return PyInt_FromLong(-1L);
372 do_strip(PyObject
*args
, int striptype
)
378 if (!PyArg_Parse(args
, "t#", &s
, &len
))
382 if (striptype
!= RIGHTSTRIP
) {
383 while (i
< len
&& isspace(Py_CHARMASK(s
[i
]))) {
389 if (striptype
!= LEFTSTRIP
) {
392 } while (j
>= i
&& isspace(Py_CHARMASK(s
[j
])));
396 if (i
== 0 && j
== len
) {
401 return PyString_FromStringAndSize(s
+i
, j
-i
);
405 static char strip__doc__
[] =
406 "strip(s) -> string\n\
408 Return a copy of the string s with leading and trailing\n\
409 whitespace removed.";
412 strop_strip(PyObject
*self
, PyObject
*args
)
414 return do_strip(args
, BOTHSTRIP
);
418 static char lstrip__doc__
[] =
419 "lstrip(s) -> string\n\
421 Return a copy of the string s with leading whitespace removed.";
424 strop_lstrip(PyObject
*self
, PyObject
*args
)
426 return do_strip(args
, LEFTSTRIP
);
430 static char rstrip__doc__
[] =
431 "rstrip(s) -> string\n\
433 Return a copy of the string s with trailing whitespace removed.";
436 strop_rstrip(PyObject
*self
, PyObject
*args
)
438 return do_strip(args
, RIGHTSTRIP
);
442 static char lower__doc__
[] =
443 "lower(s) -> string\n\
445 Return a copy of the string s converted to lowercase.";
448 strop_lower(PyObject
*self
, PyObject
*args
)
455 if (!PyArg_Parse(args
, "t#", &s
, &n
))
457 new = PyString_FromStringAndSize(NULL
, n
);
460 s_new
= PyString_AsString(new);
462 for (i
= 0; i
< n
; i
++) {
463 int c
= Py_CHARMASK(*s
++);
480 static char upper__doc__
[] =
481 "upper(s) -> string\n\
483 Return a copy of the string s converted to uppercase.";
486 strop_upper(PyObject
*self
, PyObject
*args
)
493 if (!PyArg_Parse(args
, "t#", &s
, &n
))
495 new = PyString_FromStringAndSize(NULL
, n
);
498 s_new
= PyString_AsString(new);
500 for (i
= 0; i
< n
; i
++) {
501 int c
= Py_CHARMASK(*s
++);
518 static char capitalize__doc__
[] =
519 "capitalize(s) -> string\n\
521 Return a copy of the string s with only its first character\n\
525 strop_capitalize(PyObject
*self
, PyObject
*args
)
532 if (!PyArg_Parse(args
, "t#", &s
, &n
))
534 new = PyString_FromStringAndSize(NULL
, n
);
537 s_new
= PyString_AsString(new);
540 int c
= Py_CHARMASK(*s
++);
548 for (i
= 1; i
< n
; i
++) {
549 int c
= Py_CHARMASK(*s
++);
566 static char expandtabs__doc__
[] =
567 "expandtabs(string, [tabsize]) -> string\n\
569 Expand tabs in a string, i.e. replace them by one or more spaces,\n\
570 depending on the current column and the given tab size (default 8).\n\
571 The column number is reset to zero after each newline occurring in the\n\
572 string. This doesn't understand other non-printing characters.";
575 strop_expandtabs(PyObject
*self
, PyObject
*args
)
577 /* Original by Fredrik Lundh */
588 if (!PyArg_ParseTuple(args
, "s#|i:expandtabs", &string
, &stringlen
, &tabsize
))
591 PyErr_SetString(PyExc_ValueError
,
592 "tabsize must be at least 1");
596 /* First pass: determine size of output string */
597 i
= j
= 0; /* j: current column; i: total of previous lines */
598 e
= string
+ stringlen
;
599 for (p
= string
; p
< e
; p
++) {
601 j
+= tabsize
- (j
%tabsize
);
611 /* Second pass: create output string and fill it */
612 out
= PyString_FromStringAndSize(NULL
, i
+j
);
617 q
= PyString_AS_STRING(out
);
619 for (p
= string
; p
< e
; p
++) {
621 j
= tabsize
- (i
%tabsize
);
637 static char count__doc__
[] =
638 "count(s, sub[, start[, end]]) -> int\n\
640 Return the number of occurrences of substring sub in string\n\
641 s[start:end]. Optional arguments start and end are\n\
642 interpreted as in slice notation.";
645 strop_count(PyObject
*self
, PyObject
*args
)
649 int i
= 0, last
= INT_MAX
;
652 if (!PyArg_ParseTuple(args
, "t#t#|ii:count", &s
, &len
, &sub
, &n
, &i
, &last
))
666 return PyInt_FromLong((long) (m
-i
));
670 if (!memcmp(s
+i
, sub
, n
)) {
677 return PyInt_FromLong((long) r
);
681 static char swapcase__doc__
[] =
682 "swapcase(s) -> string\n\
684 Return a copy of the string s with upper case characters\n\
685 converted to lowercase and vice versa.";
688 strop_swapcase(PyObject
*self
, PyObject
*args
)
695 if (!PyArg_Parse(args
, "t#", &s
, &n
))
697 new = PyString_FromStringAndSize(NULL
, n
);
700 s_new
= PyString_AsString(new);
702 for (i
= 0; i
< n
; i
++) {
703 int c
= Py_CHARMASK(*s
++);
708 else if (isupper(c
)) {
725 static char atoi__doc__
[] =
726 "atoi(s [,base]) -> int\n\
728 Return the integer represented by the string s in the given\n\
729 base, which defaults to 10. The string s must consist of one\n\
730 or more digits, possibly preceded by a sign. If base is 0, it\n\
731 is chosen from the leading characters of s, 0 for octal, 0x or\n\
732 0X for hexadecimal. If base is 16, a preceding 0x or 0X is\n\
736 strop_atoi(PyObject
*self
, PyObject
*args
)
741 char buffer
[256]; /* For errors */
743 if (!PyArg_ParseTuple(args
, "s|i:atoi", &s
, &base
))
746 if ((base
!= 0 && base
< 2) || base
> 36) {
747 PyErr_SetString(PyExc_ValueError
, "invalid base for atoi()");
751 while (*s
&& isspace(Py_CHARMASK(*s
)))
754 if (base
== 0 && s
[0] == '0')
755 x
= (long) PyOS_strtoul(s
, &end
, base
);
757 x
= PyOS_strtol(s
, &end
, base
);
758 if (end
== s
|| !isalnum(end
[-1]))
760 while (*end
&& isspace(Py_CHARMASK(*end
)))
764 sprintf(buffer
, "invalid literal for atoi(): %.200s", s
);
765 PyErr_SetString(PyExc_ValueError
, buffer
);
768 else if (errno
!= 0) {
769 sprintf(buffer
, "atoi() literal too large: %.200s", s
);
770 PyErr_SetString(PyExc_ValueError
, buffer
);
773 return PyInt_FromLong(x
);
777 static char atol__doc__
[] =
778 "atol(s [,base]) -> long\n\
780 Return the long integer represented by the string s in the\n\
781 given base, which defaults to 10. The string s must consist\n\
782 of one or more digits, possibly preceded by a sign. If base\n\
783 is 0, it is chosen from the leading characters of s, 0 for\n\
784 octal, 0x or 0X for hexadecimal. If base is 16, a preceding\n\
785 0x or 0X is accepted. A trailing L or l is not accepted,\n\
789 strop_atol(PyObject
*self
, PyObject
*args
)
794 char buffer
[256]; /* For errors */
796 if (!PyArg_ParseTuple(args
, "s|i:atol", &s
, &base
))
799 if ((base
!= 0 && base
< 2) || base
> 36) {
800 PyErr_SetString(PyExc_ValueError
, "invalid base for atol()");
804 while (*s
&& isspace(Py_CHARMASK(*s
)))
807 PyErr_SetString(PyExc_ValueError
, "empty string for atol()");
810 x
= PyLong_FromString(s
, &end
, base
);
813 if (base
== 0 && (*end
== 'l' || *end
== 'L'))
815 while (*end
&& isspace(Py_CHARMASK(*end
)))
818 sprintf(buffer
, "invalid literal for atol(): %.200s", s
);
819 PyErr_SetString(PyExc_ValueError
, buffer
);
827 static char atof__doc__
[] =
830 Return the floating point number represented by the string s.";
833 strop_atof(PyObject
*self
, PyObject
*args
)
835 extern double strtod(const char *, char **);
838 char buffer
[256]; /* For errors */
840 if (!PyArg_ParseTuple(args
, "s:atof", &s
))
842 while (*s
&& isspace(Py_CHARMASK(*s
)))
845 PyErr_SetString(PyExc_ValueError
, "empty string for atof()");
849 PyFPE_START_PROTECT("strop_atof", return 0)
852 while (*end
&& isspace(Py_CHARMASK(*end
)))
855 sprintf(buffer
, "invalid literal for atof(): %.200s", s
);
856 PyErr_SetString(PyExc_ValueError
, buffer
);
859 else if (errno
!= 0) {
860 sprintf(buffer
, "atof() literal too large: %.200s", s
);
861 PyErr_SetString(PyExc_ValueError
, buffer
);
864 return PyFloat_FromDouble(x
);
868 static char maketrans__doc__
[] =
869 "maketrans(frm, to) -> string\n\
871 Return a translation table (a string of 256 bytes long)\n\
872 suitable for use in string.translate. The strings frm and to\n\
873 must be of the same length.";
876 strop_maketrans(PyObject
*self
, PyObject
*args
)
878 unsigned char *c
, *from
=NULL
, *to
=NULL
;
879 int i
, fromlen
=0, tolen
=0;
882 if (!PyArg_ParseTuple(args
, "t#t#:maketrans", &from
, &fromlen
, &to
, &tolen
))
885 if (fromlen
!= tolen
) {
886 PyErr_SetString(PyExc_ValueError
,
887 "maketrans arguments must have same length");
891 result
= PyString_FromStringAndSize((char *)NULL
, 256);
894 c
= (unsigned char *) PyString_AS_STRING((PyStringObject
*)result
);
895 for (i
= 0; i
< 256; i
++)
896 c
[i
]=(unsigned char)i
;
897 for (i
= 0; i
< fromlen
; i
++)
904 static char translate__doc__
[] =
905 "translate(s,table [,deletechars]) -> string\n\
907 Return a copy of the string s, where all characters occurring\n\
908 in the optional argument deletechars are removed, and the\n\
909 remaining characters have been mapped through the given\n\
910 translation table, which must be a string of length 256.";
913 strop_translate(PyObject
*self
, PyObject
*args
)
915 register char *input
, *table
, *output
;
916 register int i
, c
, changed
= 0;
918 char *table1
, *output_start
, *del_table
=NULL
;
919 int inlen
, tablen
, dellen
= 0;
921 int trans_table
[256];
923 if (!PyArg_ParseTuple(args
, "St#|t#:translate", &input_obj
,
924 &table1
, &tablen
, &del_table
, &dellen
))
927 PyErr_SetString(PyExc_ValueError
,
928 "translation table must be 256 characters long");
933 inlen
= PyString_Size(input_obj
);
934 result
= PyString_FromStringAndSize((char *)NULL
, inlen
);
937 output_start
= output
= PyString_AsString(result
);
938 input
= PyString_AsString(input_obj
);
941 /* If no deletions are required, use faster code */
942 for (i
= inlen
; --i
>= 0; ) {
943 c
= Py_CHARMASK(*input
++);
944 if (Py_CHARMASK((*output
++ = table
[c
])) != c
)
950 Py_INCREF(input_obj
);
954 for (i
= 0; i
< 256; i
++)
955 trans_table
[i
] = Py_CHARMASK(table
[i
]);
957 for (i
= 0; i
< dellen
; i
++)
958 trans_table
[(int) Py_CHARMASK(del_table
[i
])] = -1;
960 for (i
= inlen
; --i
>= 0; ) {
961 c
= Py_CHARMASK(*input
++);
962 if (trans_table
[c
] != -1)
963 if (Py_CHARMASK(*output
++ = (char)trans_table
[c
]) == c
)
969 Py_INCREF(input_obj
);
972 /* Fix the size of the resulting string */
973 if (inlen
> 0 &&_PyString_Resize(&result
, output
-output_start
))
979 /* What follows is used for implementing replace(). Perry Stoll. */
984 strstr replacement for arbitrary blocks of memory.
986 Locates the first occurrence in the memory pointed to by MEM of the
987 contents of memory pointed to by PAT. Returns the index into MEM if
988 found, or -1 if not found. If len of PAT is greater than length of
989 MEM, the function returns -1.
991 static int mymemfind(char *mem
, int len
, char *pat
, int pat_len
)
995 /* pattern can not occur in the last pat_len-1 chars */
998 for (ii
= 0; ii
<= len
; ii
++) {
999 if (mem
[ii
] == pat
[0] &&
1001 memcmp(&mem
[ii
+1], &pat
[1], pat_len
-1) == 0)) {
1011 Return the number of distinct times PAT is found in MEM.
1012 meaning mem=1111 and pat==11 returns 2.
1013 mem=11111 and pat==11 also return 2.
1015 static int mymemcnt(char *mem
, int len
, char *pat
, int pat_len
)
1017 register int offset
= 0;
1021 offset
= mymemfind(mem
, len
, pat
, pat_len
);
1024 mem
+= offset
+ pat_len
;
1025 len
-= offset
+ pat_len
;
1034 Return a string in which all occurrences of PAT in memory STR are
1037 If length of PAT is less than length of STR or there are no occurrences
1038 of PAT in STR, then the original string is returned. Otherwise, a new
1039 string is allocated here and returned.
1041 on return, out_len is:
1042 the length of output string, or
1043 -1 if the input string is returned, or
1044 unchanged if an error occurs (no memory).
1047 the new string allocated locally, or
1048 NULL if an error occurred.
1050 static char *mymemreplace(char *str
, int len
, char *pat
, int pat_len
, char *sub
, int sub_len
, int count
, int *out_len
)
1054 int nfound
, offset
, new_len
;
1056 if (len
== 0 || pat_len
> len
)
1059 /* find length of output string */
1060 nfound
= mymemcnt(str
, len
, pat
, pat_len
);
1062 nfound
= nfound
> count
? count
: nfound
;
1065 new_len
= len
+ nfound
*(sub_len
- pat_len
);
1067 new_s
= (char *)PyMem_MALLOC(new_len
);
1068 if (new_s
== NULL
) return NULL
;
1074 /* find index of next instance of pattern */
1075 offset
= mymemfind(str
, len
, pat
, pat_len
);
1076 /* if not found, break out of loop */
1077 if (offset
== -1) break;
1079 /* copy non matching part of input string */
1080 memcpy(new_s
, str
, offset
); /* copy part of str before pat */
1081 str
+= offset
+ pat_len
; /* move str past pattern */
1082 len
-= offset
+ pat_len
; /* reduce length of str remaining */
1084 /* copy substitute into the output string */
1085 new_s
+= offset
; /* move new_s to dest for sub string */
1086 memcpy(new_s
, sub
, sub_len
); /* copy substring into new_s */
1087 new_s
+= sub_len
; /* offset new_s past sub string */
1089 /* break when we've done count replacements */
1090 if (--count
== 0) break;
1092 /* copy any remaining values into output string */
1094 memcpy(new_s
, str
, len
);
1103 static char replace__doc__
[] =
1104 "replace (str, old, new[, maxsplit]) -> string\n\
1106 Return a copy of string str with all occurrences of substring\n\
1107 old replaced by new. If the optional argument maxsplit is\n\
1108 given, only the first maxsplit occurrences are replaced.";
1111 strop_replace(PyObject
*self
, PyObject
*args
)
1113 char *str
, *pat
,*sub
,*new_s
;
1114 int len
,pat_len
,sub_len
,out_len
;
1118 if (!PyArg_ParseTuple(args
, "t#t#t#|i:replace",
1119 &str
, &len
, &pat
, &pat_len
, &sub
, &sub_len
,
1123 PyErr_SetString(PyExc_ValueError
, "empty pattern string");
1126 new_s
= mymemreplace(str
,len
,pat
,pat_len
,sub
,sub_len
,count
,&out_len
);
1127 if (new_s
== NULL
) {
1131 if (out_len
== -1) {
1132 /* we're returning another reference to the input string */
1133 new = PyTuple_GetItem(args
, 0);
1137 new = PyString_FromStringAndSize(new_s
, out_len
);
1144 /* List of functions defined in the module */
1148 {"atof", strop_atof
,
1149 METH_VARARGS
, atof__doc__
},
1150 {"atoi", strop_atoi
,
1151 METH_VARARGS
, atoi__doc__
},
1152 {"atol", strop_atol
,
1153 METH_VARARGS
, atol__doc__
},
1154 {"capitalize", strop_capitalize
,
1155 METH_OLDARGS
, capitalize__doc__
},
1156 {"count", strop_count
,
1157 METH_VARARGS
, count__doc__
},
1158 {"expandtabs", strop_expandtabs
,
1159 METH_VARARGS
, expandtabs__doc__
},
1160 {"find", strop_find
,
1161 METH_VARARGS
, find__doc__
},
1162 {"join", strop_joinfields
,
1163 METH_VARARGS
, joinfields__doc__
},
1164 {"joinfields", strop_joinfields
,
1165 METH_VARARGS
, joinfields__doc__
},
1166 {"lstrip", strop_lstrip
,
1167 METH_OLDARGS
, lstrip__doc__
},
1168 {"lower", strop_lower
,
1169 METH_OLDARGS
, lower__doc__
},
1170 {"maketrans", strop_maketrans
,
1171 METH_VARARGS
, maketrans__doc__
},
1172 {"replace", strop_replace
,
1173 METH_VARARGS
, replace__doc__
},
1174 {"rfind", strop_rfind
,
1175 METH_VARARGS
, rfind__doc__
},
1176 {"rstrip", strop_rstrip
,
1177 METH_OLDARGS
, rstrip__doc__
},
1178 {"split", strop_splitfields
,
1179 METH_VARARGS
, splitfields__doc__
},
1180 {"splitfields", strop_splitfields
,
1181 METH_VARARGS
, splitfields__doc__
},
1182 {"strip", strop_strip
,
1183 METH_OLDARGS
, strip__doc__
},
1184 {"swapcase", strop_swapcase
,
1185 METH_OLDARGS
, swapcase__doc__
},
1186 {"translate", strop_translate
,
1187 METH_VARARGS
, translate__doc__
},
1188 {"upper", strop_upper
,
1189 METH_OLDARGS
, upper__doc__
},
1190 {NULL
, NULL
} /* sentinel */
1197 PyObject
*m
, *d
, *s
;
1200 m
= Py_InitModule4("strop", strop_methods
, strop_module__doc__
,
1201 (PyObject
*)NULL
, PYTHON_API_VERSION
);
1202 d
= PyModule_GetDict(m
);
1204 /* Create 'whitespace' object */
1206 for (c
= 0; c
< 256; c
++) {
1210 s
= PyString_FromStringAndSize(buf
, n
);
1212 PyDict_SetItemString(d
, "whitespace", s
);
1215 /* Create 'lowercase' object */
1217 for (c
= 0; c
< 256; c
++) {
1221 s
= PyString_FromStringAndSize(buf
, n
);
1223 PyDict_SetItemString(d
, "lowercase", s
);
1227 /* Create 'uppercase' object */
1229 for (c
= 0; c
< 256; c
++) {
1233 s
= PyString_FromStringAndSize(buf
, n
);
1235 PyDict_SetItemString(d
, "uppercase", s
);