3 static char strop_module__doc__
[] =
4 "Common string manipulations, optimized for speed.\n"
6 "Always use \"import string\" rather than referencing\n"
7 "this module directly.";
12 /* XXX This file assumes that the <ctype.h> is*() functions
13 XXX are defined for all 8-bit characters! */
15 #define WARN if (PyErr_Warn(PyExc_DeprecationWarning, \
16 "strop functions are obsolete; use string methods")) \
19 /* The lstrip(), rstrip() and strip() functions are implemented
20 in do_strip(), which uses an additional parameter to indicate what
21 type of strip should occur. */
29 split_whitespace(char *s
, int len
, int maxsplit
)
34 PyObject
*list
= PyList_New(0);
40 while (i
< len
&& isspace(Py_CHARMASK(s
[i
]))) {
44 while (i
< len
&& !isspace(Py_CHARMASK(s
[i
]))) {
48 item
= PyString_FromStringAndSize(s
+j
, (int)(i
-j
));
52 err
= PyList_Append(list
, item
);
58 while (i
< len
&& isspace(Py_CHARMASK(s
[i
]))) {
61 if (maxsplit
&& (countsplit
>= maxsplit
) && i
< len
) {
62 item
= PyString_FromStringAndSize(
67 err
= PyList_Append(list
, item
);
83 static char splitfields__doc__
[] =
84 "split(s [,sep [,maxsplit]]) -> list of strings\n"
85 "splitfields(s [,sep [,maxsplit]]) -> list of strings\n"
87 "Return a list of the words in the string s, using sep as the\n"
88 "delimiter string. If maxsplit is nonzero, splits into at most\n"
89 "maxsplit words. If sep is not specified, any whitespace string\n"
90 "is a separator. Maxsplit defaults to 0.\n"
92 "(split and splitfields are synonymous)";
95 strop_splitfields(PyObject
*self
, PyObject
*args
)
97 int len
, n
, i
, j
, err
;
98 int splitcount
, maxsplit
;
100 PyObject
*list
, *item
;
107 if (!PyArg_ParseTuple(args
, "t#|z#i:split", &s
, &len
, &sub
, &n
, &maxsplit
))
110 return split_whitespace(s
, len
, maxsplit
);
112 PyErr_SetString(PyExc_ValueError
, "empty separator");
116 list
= PyList_New(0);
122 if (s
[i
] == sub
[0] && (n
== 1 || memcmp(s
+i
, sub
, n
) == 0)) {
123 item
= PyString_FromStringAndSize(s
+j
, (int)(i
-j
));
126 err
= PyList_Append(list
, item
);
132 if (maxsplit
&& (splitcount
>= maxsplit
))
138 item
= PyString_FromStringAndSize(s
+j
, (int)(len
-j
));
141 err
= PyList_Append(list
, item
);
154 static char joinfields__doc__
[] =
155 "join(list [,sep]) -> string\n"
156 "joinfields(list [,sep]) -> string\n"
158 "Return a string composed of the words in list, with\n"
159 "intervening occurrences of sep. Sep defaults to a single\n"
162 "(join and joinfields are synonymous)";
165 strop_joinfields(PyObject
*self
, PyObject
*args
)
169 int seqlen
, seplen
= 0;
170 int i
, reslen
= 0, slen
= 0, sz
= 100;
171 PyObject
*res
= NULL
;
173 intargfunc getitemfunc
;
176 if (!PyArg_ParseTuple(args
, "O|t#:join", &seq
, &sep
, &seplen
))
183 seqlen
= PySequence_Size(seq
);
184 if (seqlen
< 0 && PyErr_Occurred())
188 /* Optimization if there's only one item */
189 PyObject
*item
= PySequence_GetItem(seq
, 0);
190 if (item
&& !PyString_Check(item
)) {
191 PyErr_SetString(PyExc_TypeError
,
192 "first argument must be sequence of strings");
199 if (!(res
= PyString_FromStringAndSize((char*)NULL
, sz
)))
201 p
= PyString_AsString(res
);
203 /* optimize for lists, since it's the most common case. all others
204 * (tuples and arbitrary sequences) just use the sequence abstract
207 if (PyList_Check(seq
)) {
208 for (i
= 0; i
< seqlen
; i
++) {
209 PyObject
*item
= PyList_GET_ITEM(seq
, i
);
210 if (!PyString_Check(item
)) {
211 PyErr_SetString(PyExc_TypeError
,
212 "first argument must be sequence of strings");
216 slen
= PyString_GET_SIZE(item
);
217 while (reslen
+ slen
+ seplen
>= sz
) {
218 if (_PyString_Resize(&res
, sz
* 2)) {
223 p
= PyString_AsString(res
) + reslen
;
226 memcpy(p
, sep
, seplen
);
230 memcpy(p
, PyString_AS_STRING(item
), slen
);
234 if (_PyString_Resize(&res
, reslen
)) {
241 if (seq
->ob_type
->tp_as_sequence
== NULL
||
242 (getitemfunc
= seq
->ob_type
->tp_as_sequence
->sq_item
) == NULL
)
244 PyErr_SetString(PyExc_TypeError
,
245 "first argument must be a sequence");
248 /* This is now type safe */
249 for (i
= 0; i
< seqlen
; i
++) {
250 PyObject
*item
= getitemfunc(seq
, i
);
251 if (!item
|| !PyString_Check(item
)) {
252 PyErr_SetString(PyExc_TypeError
,
253 "first argument must be sequence of strings");
258 slen
= PyString_GET_SIZE(item
);
259 while (reslen
+ slen
+ seplen
>= sz
) {
260 if (_PyString_Resize(&res
, sz
* 2)) {
266 p
= PyString_AsString(res
) + reslen
;
269 memcpy(p
, sep
, seplen
);
273 memcpy(p
, PyString_AS_STRING(item
), slen
);
278 if (_PyString_Resize(&res
, reslen
)) {
286 static char find__doc__
[] =
287 "find(s, sub [,start [,end]]) -> in\n"
289 "Return the lowest index in s where substring sub is found,\n"
290 "such that sub is contained within s[start,end]. Optional\n"
291 "arguments start and end are interpreted as in slice notation.\n"
293 "Return -1 on failure.";
296 strop_find(PyObject
*self
, PyObject
*args
)
299 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
;
346 if (!PyArg_ParseTuple(args
, "t#t#|ii:rfind", &s
, &len
, &sub
, &n
, &i
, &last
))
360 if (n
== 0 && i
<= last
)
361 return PyInt_FromLong((long)last
);
363 for (j
= last
-n
; j
>= i
; --j
)
364 if (s
[j
] == sub
[0] &&
365 (n
== 1 || memcmp(&s
[j
+1], &sub
[1], n
-1) == 0))
366 return PyInt_FromLong((long)j
);
368 return PyInt_FromLong(-1L);
373 do_strip(PyObject
*args
, int striptype
)
379 if (!PyArg_Parse(args
, "t#", &s
, &len
))
383 if (striptype
!= RIGHTSTRIP
) {
384 while (i
< len
&& isspace(Py_CHARMASK(s
[i
]))) {
390 if (striptype
!= LEFTSTRIP
) {
393 } while (j
>= i
&& isspace(Py_CHARMASK(s
[j
])));
397 if (i
== 0 && j
== len
) {
402 return PyString_FromStringAndSize(s
+i
, j
-i
);
406 static char strip__doc__
[] =
407 "strip(s) -> string\n"
409 "Return a copy of the string s with leading and trailing\n"
410 "whitespace removed.";
413 strop_strip(PyObject
*self
, PyObject
*args
)
416 return do_strip(args
, BOTHSTRIP
);
420 static char lstrip__doc__
[] =
421 "lstrip(s) -> string\n"
423 "Return a copy of the string s with leading whitespace removed.";
426 strop_lstrip(PyObject
*self
, PyObject
*args
)
429 return do_strip(args
, LEFTSTRIP
);
433 static char rstrip__doc__
[] =
434 "rstrip(s) -> string\n"
436 "Return a copy of the string s with trailing whitespace removed.";
439 strop_rstrip(PyObject
*self
, PyObject
*args
)
442 return do_strip(args
, RIGHTSTRIP
);
446 static char lower__doc__
[] =
447 "lower(s) -> string\n"
449 "Return a copy of the string s converted to lowercase.";
452 strop_lower(PyObject
*self
, PyObject
*args
)
460 if (!PyArg_Parse(args
, "t#", &s
, &n
))
462 new = PyString_FromStringAndSize(NULL
, n
);
465 s_new
= PyString_AsString(new);
467 for (i
= 0; i
< n
; i
++) {
468 int c
= Py_CHARMASK(*s
++);
485 static char upper__doc__
[] =
486 "upper(s) -> string\n"
488 "Return a copy of the string s converted to uppercase.";
491 strop_upper(PyObject
*self
, PyObject
*args
)
499 if (!PyArg_Parse(args
, "t#", &s
, &n
))
501 new = PyString_FromStringAndSize(NULL
, n
);
504 s_new
= PyString_AsString(new);
506 for (i
= 0; i
< n
; i
++) {
507 int c
= Py_CHARMASK(*s
++);
524 static char capitalize__doc__
[] =
525 "capitalize(s) -> string\n"
527 "Return a copy of the string s with only its first character\n"
531 strop_capitalize(PyObject
*self
, PyObject
*args
)
539 if (!PyArg_Parse(args
, "t#", &s
, &n
))
541 new = PyString_FromStringAndSize(NULL
, n
);
544 s_new
= PyString_AsString(new);
547 int c
= Py_CHARMASK(*s
++);
555 for (i
= 1; i
< n
; i
++) {
556 int c
= Py_CHARMASK(*s
++);
573 static char expandtabs__doc__
[] =
574 "expandtabs(string, [tabsize]) -> string\n"
576 "Expand tabs in a string, i.e. replace them by one or more spaces,\n"
577 "depending on the current column and the given tab size (default 8).\n"
578 "The column number is reset to zero after each newline occurring in the\n"
579 "string. This doesn't understand other non-printing characters.";
582 strop_expandtabs(PyObject
*self
, PyObject
*args
)
584 /* Original by Fredrik Lundh */
596 if (!PyArg_ParseTuple(args
, "s#|i:expandtabs", &string
, &stringlen
, &tabsize
))
599 PyErr_SetString(PyExc_ValueError
,
600 "tabsize must be at least 1");
604 /* First pass: determine size of output string */
605 i
= j
= 0; /* j: current column; i: total of previous lines */
606 e
= string
+ stringlen
;
607 for (p
= string
; p
< e
; p
++) {
609 j
+= tabsize
- (j
%tabsize
);
619 /* Second pass: create output string and fill it */
620 out
= PyString_FromStringAndSize(NULL
, i
+j
);
625 q
= PyString_AS_STRING(out
);
627 for (p
= string
; p
< e
; p
++) {
629 j
= tabsize
- (i
%tabsize
);
645 static char count__doc__
[] =
646 "count(s, sub[, start[, end]]) -> int\n"
648 "Return the number of occurrences of substring sub in string\n"
649 "s[start:end]. Optional arguments start and end are\n"
650 "interpreted as in slice notation.";
653 strop_count(PyObject
*self
, PyObject
*args
)
657 int i
= 0, last
= INT_MAX
;
661 if (!PyArg_ParseTuple(args
, "t#t#|ii:count", &s
, &len
, &sub
, &n
, &i
, &last
))
675 return PyInt_FromLong((long) (m
-i
));
679 if (!memcmp(s
+i
, sub
, n
)) {
686 return PyInt_FromLong((long) r
);
690 static char swapcase__doc__
[] =
691 "swapcase(s) -> string\n"
693 "Return a copy of the string s with upper case characters\n"
694 "converted to lowercase and vice versa.";
697 strop_swapcase(PyObject
*self
, PyObject
*args
)
705 if (!PyArg_Parse(args
, "t#", &s
, &n
))
707 new = PyString_FromStringAndSize(NULL
, n
);
710 s_new
= PyString_AsString(new);
712 for (i
= 0; i
< n
; i
++) {
713 int c
= Py_CHARMASK(*s
++);
718 else if (isupper(c
)) {
735 static char atoi__doc__
[] =
736 "atoi(s [,base]) -> int\n"
738 "Return the integer represented by the string s in the given\n"
739 "base, which defaults to 10. The string s must consist of one\n"
740 "or more digits, possibly preceded by a sign. If base is 0, it\n"
741 "is chosen from the leading characters of s, 0 for octal, 0x or\n"
742 "0X for hexadecimal. If base is 16, a preceding 0x or 0X is\n"
746 strop_atoi(PyObject
*self
, PyObject
*args
)
751 char buffer
[256]; /* For errors */
754 if (!PyArg_ParseTuple(args
, "s|i:atoi", &s
, &base
))
757 if ((base
!= 0 && base
< 2) || base
> 36) {
758 PyErr_SetString(PyExc_ValueError
, "invalid base for atoi()");
762 while (*s
&& isspace(Py_CHARMASK(*s
)))
765 if (base
== 0 && s
[0] == '0')
766 x
= (long) PyOS_strtoul(s
, &end
, base
);
768 x
= PyOS_strtol(s
, &end
, base
);
769 if (end
== s
|| !isalnum(end
[-1]))
771 while (*end
&& isspace(Py_CHARMASK(*end
)))
775 sprintf(buffer
, "invalid literal for atoi(): %.200s", s
);
776 PyErr_SetString(PyExc_ValueError
, buffer
);
779 else if (errno
!= 0) {
780 sprintf(buffer
, "atoi() literal too large: %.200s", s
);
781 PyErr_SetString(PyExc_ValueError
, buffer
);
784 return PyInt_FromLong(x
);
788 static char atol__doc__
[] =
789 "atol(s [,base]) -> long\n"
791 "Return the long integer represented by the string s in the\n"
792 "given base, which defaults to 10. The string s must consist\n"
793 "of one or more digits, possibly preceded by a sign. If base\n"
794 "is 0, it is chosen from the leading characters of s, 0 for\n"
795 "octal, 0x or 0X for hexadecimal. If base is 16, a preceding\n"
796 "0x or 0X is accepted. A trailing L or l is not accepted,\n"
800 strop_atol(PyObject
*self
, PyObject
*args
)
805 char buffer
[256]; /* For errors */
808 if (!PyArg_ParseTuple(args
, "s|i:atol", &s
, &base
))
811 if ((base
!= 0 && base
< 2) || base
> 36) {
812 PyErr_SetString(PyExc_ValueError
, "invalid base for atol()");
816 while (*s
&& isspace(Py_CHARMASK(*s
)))
819 PyErr_SetString(PyExc_ValueError
, "empty string for atol()");
822 x
= PyLong_FromString(s
, &end
, base
);
825 if (base
== 0 && (*end
== 'l' || *end
== 'L'))
827 while (*end
&& isspace(Py_CHARMASK(*end
)))
830 sprintf(buffer
, "invalid literal for atol(): %.200s", s
);
831 PyErr_SetString(PyExc_ValueError
, buffer
);
839 static char atof__doc__
[] =
842 "Return the floating point number represented by the string s.";
845 strop_atof(PyObject
*self
, PyObject
*args
)
847 extern double strtod(const char *, char **);
850 char buffer
[256]; /* For errors */
853 if (!PyArg_ParseTuple(args
, "s:atof", &s
))
855 while (*s
&& isspace(Py_CHARMASK(*s
)))
858 PyErr_SetString(PyExc_ValueError
, "empty string for atof()");
862 PyFPE_START_PROTECT("strop_atof", return 0)
865 while (*end
&& isspace(Py_CHARMASK(*end
)))
868 sprintf(buffer
, "invalid literal for atof(): %.200s", s
);
869 PyErr_SetString(PyExc_ValueError
, buffer
);
872 else if (errno
!= 0) {
873 sprintf(buffer
, "atof() literal too large: %.200s", s
);
874 PyErr_SetString(PyExc_ValueError
, buffer
);
877 return PyFloat_FromDouble(x
);
881 static char maketrans__doc__
[] =
882 "maketrans(frm, to) -> string\n"
884 "Return a translation table (a string of 256 bytes long)\n"
885 "suitable for use in string.translate. The strings frm and to\n"
886 "must be of the same length.";
889 strop_maketrans(PyObject
*self
, PyObject
*args
)
891 unsigned char *c
, *from
=NULL
, *to
=NULL
;
892 int i
, fromlen
=0, tolen
=0;
895 if (!PyArg_ParseTuple(args
, "t#t#:maketrans", &from
, &fromlen
, &to
, &tolen
))
898 if (fromlen
!= tolen
) {
899 PyErr_SetString(PyExc_ValueError
,
900 "maketrans arguments must have same length");
904 result
= PyString_FromStringAndSize((char *)NULL
, 256);
907 c
= (unsigned char *) PyString_AS_STRING((PyStringObject
*)result
);
908 for (i
= 0; i
< 256; i
++)
909 c
[i
]=(unsigned char)i
;
910 for (i
= 0; i
< fromlen
; i
++)
917 static char translate__doc__
[] =
918 "translate(s,table [,deletechars]) -> string\n"
920 "Return a copy of the string s, where all characters occurring\n"
921 "in the optional argument deletechars are removed, and the\n"
922 "remaining characters have been mapped through the given\n"
923 "translation table, which must be a string of length 256.";
926 strop_translate(PyObject
*self
, PyObject
*args
)
928 register char *input
, *table
, *output
;
929 register int i
, c
, changed
= 0;
931 char *table1
, *output_start
, *del_table
=NULL
;
932 int inlen
, tablen
, dellen
= 0;
934 int trans_table
[256];
937 if (!PyArg_ParseTuple(args
, "St#|t#:translate", &input_obj
,
938 &table1
, &tablen
, &del_table
, &dellen
))
941 PyErr_SetString(PyExc_ValueError
,
942 "translation table must be 256 characters long");
947 inlen
= PyString_Size(input_obj
);
948 result
= PyString_FromStringAndSize((char *)NULL
, inlen
);
951 output_start
= output
= PyString_AsString(result
);
952 input
= PyString_AsString(input_obj
);
955 /* If no deletions are required, use faster code */
956 for (i
= inlen
; --i
>= 0; ) {
957 c
= Py_CHARMASK(*input
++);
958 if (Py_CHARMASK((*output
++ = table
[c
])) != c
)
964 Py_INCREF(input_obj
);
968 for (i
= 0; i
< 256; i
++)
969 trans_table
[i
] = Py_CHARMASK(table
[i
]);
971 for (i
= 0; i
< dellen
; i
++)
972 trans_table
[(int) Py_CHARMASK(del_table
[i
])] = -1;
974 for (i
= inlen
; --i
>= 0; ) {
975 c
= Py_CHARMASK(*input
++);
976 if (trans_table
[c
] != -1)
977 if (Py_CHARMASK(*output
++ = (char)trans_table
[c
]) == c
)
983 Py_INCREF(input_obj
);
986 /* Fix the size of the resulting string */
987 if (inlen
> 0 &&_PyString_Resize(&result
, output
-output_start
))
993 /* What follows is used for implementing replace(). Perry Stoll. */
998 strstr replacement for arbitrary blocks of memory.
1000 Locates the first occurrence in the memory pointed to by MEM of the
1001 contents of memory pointed to by PAT. Returns the index into MEM if
1002 found, or -1 if not found. If len of PAT is greater than length of
1003 MEM, the function returns -1.
1006 mymemfind(const char *mem
, int len
, const char *pat
, int pat_len
)
1010 /* pattern can not occur in the last pat_len-1 chars */
1013 for (ii
= 0; ii
<= len
; ii
++) {
1014 if (mem
[ii
] == pat
[0] &&
1016 memcmp(&mem
[ii
+1], &pat
[1], pat_len
-1) == 0)) {
1026 Return the number of distinct times PAT is found in MEM.
1027 meaning mem=1111 and pat==11 returns 2.
1028 mem=11111 and pat==11 also return 2.
1031 mymemcnt(const char *mem
, int len
, const char *pat
, int pat_len
)
1033 register int offset
= 0;
1037 offset
= mymemfind(mem
, len
, pat
, pat_len
);
1040 mem
+= offset
+ pat_len
;
1041 len
-= offset
+ pat_len
;
1050 Return a string in which all occurrences of PAT in memory STR are
1053 If length of PAT is less than length of STR or there are no occurrences
1054 of PAT in STR, then the original string is returned. Otherwise, a new
1055 string is allocated here and returned.
1057 on return, out_len is:
1058 the length of output string, or
1059 -1 if the input string is returned, or
1060 unchanged if an error occurs (no memory).
1063 the new string allocated locally, or
1064 NULL if an error occurred.
1067 mymemreplace(const char *str
, int len
, /* input string */
1068 const char *pat
, int pat_len
, /* pattern string to find */
1069 const char *sub
, int sub_len
, /* substitution string */
1070 int count
, /* number of replacements */
1075 int nfound
, offset
, new_len
;
1077 if (len
== 0 || pat_len
> len
)
1080 /* find length of output string */
1081 nfound
= mymemcnt(str
, len
, pat
, pat_len
);
1084 else if (nfound
> count
)
1089 new_len
= len
+ nfound
*(sub_len
- pat_len
);
1091 /* Have to allocate something for the caller to free(). */
1092 out_s
= (char *)PyMem_MALLOC(1);
1098 assert(new_len
> 0);
1099 new_s
= (char *)PyMem_MALLOC(new_len
);
1104 for (; count
> 0 && len
> 0; --count
) {
1105 /* find index of next instance of pattern */
1106 offset
= mymemfind(str
, len
, pat
, pat_len
);
1110 /* copy non matching part of input string */
1111 memcpy(new_s
, str
, offset
);
1112 str
+= offset
+ pat_len
;
1113 len
-= offset
+ pat_len
;
1115 /* copy substitute into the output string */
1117 memcpy(new_s
, sub
, sub_len
);
1120 /* copy any remaining values into output string */
1122 memcpy(new_s
, str
, len
);
1129 return (char *)str
; /* cast away const */
1133 static char replace__doc__
[] =
1134 "replace (str, old, new[, maxsplit]) -> string\n"
1136 "Return a copy of string str with all occurrences of substring\n"
1137 "old replaced by new. If the optional argument maxsplit is\n"
1138 "given, only the first maxsplit occurrences are replaced.";
1141 strop_replace(PyObject
*self
, PyObject
*args
)
1143 char *str
, *pat
,*sub
,*new_s
;
1144 int len
,pat_len
,sub_len
,out_len
;
1149 if (!PyArg_ParseTuple(args
, "t#t#t#|i:replace",
1150 &str
, &len
, &pat
, &pat_len
, &sub
, &sub_len
,
1154 PyErr_SetString(PyExc_ValueError
, "empty pattern string");
1157 /* CAUTION: strop treats a replace count of 0 as infinity, unlke
1158 * current (2.1) string.py and string methods. Preserve this for
1159 * ... well, hard to say for what <wink>.
1163 new_s
= mymemreplace(str
,len
,pat
,pat_len
,sub
,sub_len
,count
,&out_len
);
1164 if (new_s
== NULL
) {
1168 if (out_len
== -1) {
1169 /* we're returning another reference to the input string */
1170 new = PyTuple_GetItem(args
, 0);
1174 new = PyString_FromStringAndSize(new_s
, out_len
);
1181 /* List of functions defined in the module */
1185 {"atof", strop_atof
, METH_VARARGS
, atof__doc__
},
1186 {"atoi", strop_atoi
, METH_VARARGS
, atoi__doc__
},
1187 {"atol", strop_atol
, METH_VARARGS
, atol__doc__
},
1188 {"capitalize", strop_capitalize
, METH_OLDARGS
, capitalize__doc__
},
1189 {"count", strop_count
, METH_VARARGS
, count__doc__
},
1190 {"expandtabs", strop_expandtabs
, METH_VARARGS
, expandtabs__doc__
},
1191 {"find", strop_find
, METH_VARARGS
, find__doc__
},
1192 {"join", strop_joinfields
, METH_VARARGS
, joinfields__doc__
},
1193 {"joinfields", strop_joinfields
, METH_VARARGS
, joinfields__doc__
},
1194 {"lstrip", strop_lstrip
, METH_OLDARGS
, lstrip__doc__
},
1195 {"lower", strop_lower
, METH_OLDARGS
, lower__doc__
},
1196 {"maketrans", strop_maketrans
, METH_VARARGS
, maketrans__doc__
},
1197 {"replace", strop_replace
, METH_VARARGS
, replace__doc__
},
1198 {"rfind", strop_rfind
, METH_VARARGS
, rfind__doc__
},
1199 {"rstrip", strop_rstrip
, METH_OLDARGS
, rstrip__doc__
},
1200 {"split", strop_splitfields
, METH_VARARGS
, splitfields__doc__
},
1201 {"splitfields", strop_splitfields
, METH_VARARGS
, splitfields__doc__
},
1202 {"strip", strop_strip
, METH_OLDARGS
, strip__doc__
},
1203 {"swapcase", strop_swapcase
, METH_OLDARGS
, swapcase__doc__
},
1204 {"translate", strop_translate
, METH_VARARGS
, translate__doc__
},
1205 {"upper", strop_upper
, METH_OLDARGS
, upper__doc__
},
1206 {NULL
, NULL
} /* sentinel */
1213 PyObject
*m
, *d
, *s
;
1216 m
= Py_InitModule4("strop", strop_methods
, strop_module__doc__
,
1217 (PyObject
*)NULL
, PYTHON_API_VERSION
);
1218 d
= PyModule_GetDict(m
);
1220 /* Create 'whitespace' object */
1222 for (c
= 0; c
< 256; c
++) {
1226 s
= PyString_FromStringAndSize(buf
, n
);
1228 PyDict_SetItemString(d
, "whitespace", s
);
1231 /* Create 'lowercase' object */
1233 for (c
= 0; c
< 256; c
++) {
1237 s
= PyString_FromStringAndSize(buf
, n
);
1239 PyDict_SetItemString(d
, "lowercase", s
);
1243 /* Create 'uppercase' object */
1245 for (c
= 0; c
< 256; c
++) {
1249 s
= PyString_FromStringAndSize(buf
, n
);
1251 PyDict_SetItemString(d
, "uppercase", s
);