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 PyOS_snprintf(buffer
, sizeof(buffer
),
776 "invalid literal for atoi(): %.200s", s
);
777 PyErr_SetString(PyExc_ValueError
, buffer
);
780 else if (errno
!= 0) {
781 PyOS_snprintf(buffer
, sizeof(buffer
),
782 "atoi() literal too large: %.200s", s
);
783 PyErr_SetString(PyExc_ValueError
, buffer
);
786 return PyInt_FromLong(x
);
790 static char atol__doc__
[] =
791 "atol(s [,base]) -> long\n"
793 "Return the long integer represented by the string s in the\n"
794 "given base, which defaults to 10. The string s must consist\n"
795 "of one or more digits, possibly preceded by a sign. If base\n"
796 "is 0, it is chosen from the leading characters of s, 0 for\n"
797 "octal, 0x or 0X for hexadecimal. If base is 16, a preceding\n"
798 "0x or 0X is accepted. A trailing L or l is not accepted,\n"
802 strop_atol(PyObject
*self
, PyObject
*args
)
807 char buffer
[256]; /* For errors */
810 if (!PyArg_ParseTuple(args
, "s|i:atol", &s
, &base
))
813 if ((base
!= 0 && base
< 2) || base
> 36) {
814 PyErr_SetString(PyExc_ValueError
, "invalid base for atol()");
818 while (*s
&& isspace(Py_CHARMASK(*s
)))
821 PyErr_SetString(PyExc_ValueError
, "empty string for atol()");
824 x
= PyLong_FromString(s
, &end
, base
);
827 if (base
== 0 && (*end
== 'l' || *end
== 'L'))
829 while (*end
&& isspace(Py_CHARMASK(*end
)))
832 PyOS_snprintf(buffer
, sizeof(buffer
),
833 "invalid literal for atol(): %.200s", s
);
834 PyErr_SetString(PyExc_ValueError
, buffer
);
842 static char atof__doc__
[] =
845 "Return the floating point number represented by the string s.";
848 strop_atof(PyObject
*self
, PyObject
*args
)
850 extern double strtod(const char *, char **);
853 char buffer
[256]; /* For errors */
856 if (!PyArg_ParseTuple(args
, "s:atof", &s
))
858 while (*s
&& isspace(Py_CHARMASK(*s
)))
861 PyErr_SetString(PyExc_ValueError
, "empty string for atof()");
865 PyFPE_START_PROTECT("strop_atof", return 0)
868 while (*end
&& isspace(Py_CHARMASK(*end
)))
871 PyOS_snprintf(buffer
, sizeof(buffer
),
872 "invalid literal for atof(): %.200s", s
);
873 PyErr_SetString(PyExc_ValueError
, buffer
);
876 else if (errno
!= 0) {
877 PyOS_snprintf(buffer
, sizeof(buffer
),
878 "atof() literal too large: %.200s", s
);
879 PyErr_SetString(PyExc_ValueError
, buffer
);
882 return PyFloat_FromDouble(x
);
886 static char maketrans__doc__
[] =
887 "maketrans(frm, to) -> string\n"
889 "Return a translation table (a string of 256 bytes long)\n"
890 "suitable for use in string.translate. The strings frm and to\n"
891 "must be of the same length.";
894 strop_maketrans(PyObject
*self
, PyObject
*args
)
896 unsigned char *c
, *from
=NULL
, *to
=NULL
;
897 int i
, fromlen
=0, tolen
=0;
900 if (!PyArg_ParseTuple(args
, "t#t#:maketrans", &from
, &fromlen
, &to
, &tolen
))
903 if (fromlen
!= tolen
) {
904 PyErr_SetString(PyExc_ValueError
,
905 "maketrans arguments must have same length");
909 result
= PyString_FromStringAndSize((char *)NULL
, 256);
912 c
= (unsigned char *) PyString_AS_STRING((PyStringObject
*)result
);
913 for (i
= 0; i
< 256; i
++)
914 c
[i
]=(unsigned char)i
;
915 for (i
= 0; i
< fromlen
; i
++)
922 static char translate__doc__
[] =
923 "translate(s,table [,deletechars]) -> string\n"
925 "Return a copy of the string s, where all characters occurring\n"
926 "in the optional argument deletechars are removed, and the\n"
927 "remaining characters have been mapped through the given\n"
928 "translation table, which must be a string of length 256.";
931 strop_translate(PyObject
*self
, PyObject
*args
)
933 register char *input
, *table
, *output
;
934 register int i
, c
, changed
= 0;
936 char *table1
, *output_start
, *del_table
=NULL
;
937 int inlen
, tablen
, dellen
= 0;
939 int trans_table
[256];
942 if (!PyArg_ParseTuple(args
, "St#|t#:translate", &input_obj
,
943 &table1
, &tablen
, &del_table
, &dellen
))
946 PyErr_SetString(PyExc_ValueError
,
947 "translation table must be 256 characters long");
952 inlen
= PyString_Size(input_obj
);
953 result
= PyString_FromStringAndSize((char *)NULL
, inlen
);
956 output_start
= output
= PyString_AsString(result
);
957 input
= PyString_AsString(input_obj
);
960 /* If no deletions are required, use faster code */
961 for (i
= inlen
; --i
>= 0; ) {
962 c
= Py_CHARMASK(*input
++);
963 if (Py_CHARMASK((*output
++ = table
[c
])) != c
)
969 Py_INCREF(input_obj
);
973 for (i
= 0; i
< 256; i
++)
974 trans_table
[i
] = Py_CHARMASK(table
[i
]);
976 for (i
= 0; i
< dellen
; i
++)
977 trans_table
[(int) Py_CHARMASK(del_table
[i
])] = -1;
979 for (i
= inlen
; --i
>= 0; ) {
980 c
= Py_CHARMASK(*input
++);
981 if (trans_table
[c
] != -1)
982 if (Py_CHARMASK(*output
++ = (char)trans_table
[c
]) == c
)
988 Py_INCREF(input_obj
);
991 /* Fix the size of the resulting string */
992 if (inlen
> 0 &&_PyString_Resize(&result
, output
-output_start
))
998 /* What follows is used for implementing replace(). Perry Stoll. */
1003 strstr replacement for arbitrary blocks of memory.
1005 Locates the first occurrence in the memory pointed to by MEM of the
1006 contents of memory pointed to by PAT. Returns the index into MEM if
1007 found, or -1 if not found. If len of PAT is greater than length of
1008 MEM, the function returns -1.
1011 mymemfind(const char *mem
, int len
, const char *pat
, int pat_len
)
1015 /* pattern can not occur in the last pat_len-1 chars */
1018 for (ii
= 0; ii
<= len
; ii
++) {
1019 if (mem
[ii
] == pat
[0] &&
1021 memcmp(&mem
[ii
+1], &pat
[1], pat_len
-1) == 0)) {
1031 Return the number of distinct times PAT is found in MEM.
1032 meaning mem=1111 and pat==11 returns 2.
1033 mem=11111 and pat==11 also return 2.
1036 mymemcnt(const char *mem
, int len
, const char *pat
, int pat_len
)
1038 register int offset
= 0;
1042 offset
= mymemfind(mem
, len
, pat
, pat_len
);
1045 mem
+= offset
+ pat_len
;
1046 len
-= offset
+ pat_len
;
1055 Return a string in which all occurrences of PAT in memory STR are
1058 If length of PAT is less than length of STR or there are no occurrences
1059 of PAT in STR, then the original string is returned. Otherwise, a new
1060 string is allocated here and returned.
1062 on return, out_len is:
1063 the length of output string, or
1064 -1 if the input string is returned, or
1065 unchanged if an error occurs (no memory).
1068 the new string allocated locally, or
1069 NULL if an error occurred.
1072 mymemreplace(const char *str
, int len
, /* input string */
1073 const char *pat
, int pat_len
, /* pattern string to find */
1074 const char *sub
, int sub_len
, /* substitution string */
1075 int count
, /* number of replacements */
1080 int nfound
, offset
, new_len
;
1082 if (len
== 0 || pat_len
> len
)
1085 /* find length of output string */
1086 nfound
= mymemcnt(str
, len
, pat
, pat_len
);
1089 else if (nfound
> count
)
1094 new_len
= len
+ nfound
*(sub_len
- pat_len
);
1096 /* Have to allocate something for the caller to free(). */
1097 out_s
= (char *)PyMem_MALLOC(1);
1103 assert(new_len
> 0);
1104 new_s
= (char *)PyMem_MALLOC(new_len
);
1109 for (; count
> 0 && len
> 0; --count
) {
1110 /* find index of next instance of pattern */
1111 offset
= mymemfind(str
, len
, pat
, pat_len
);
1115 /* copy non matching part of input string */
1116 memcpy(new_s
, str
, offset
);
1117 str
+= offset
+ pat_len
;
1118 len
-= offset
+ pat_len
;
1120 /* copy substitute into the output string */
1122 memcpy(new_s
, sub
, sub_len
);
1125 /* copy any remaining values into output string */
1127 memcpy(new_s
, str
, len
);
1134 return (char *)str
; /* cast away const */
1138 static char replace__doc__
[] =
1139 "replace (str, old, new[, maxsplit]) -> string\n"
1141 "Return a copy of string str with all occurrences of substring\n"
1142 "old replaced by new. If the optional argument maxsplit is\n"
1143 "given, only the first maxsplit occurrences are replaced.";
1146 strop_replace(PyObject
*self
, PyObject
*args
)
1148 char *str
, *pat
,*sub
,*new_s
;
1149 int len
,pat_len
,sub_len
,out_len
;
1154 if (!PyArg_ParseTuple(args
, "t#t#t#|i:replace",
1155 &str
, &len
, &pat
, &pat_len
, &sub
, &sub_len
,
1159 PyErr_SetString(PyExc_ValueError
, "empty pattern string");
1162 /* CAUTION: strop treats a replace count of 0 as infinity, unlke
1163 * current (2.1) string.py and string methods. Preserve this for
1164 * ... well, hard to say for what <wink>.
1168 new_s
= mymemreplace(str
,len
,pat
,pat_len
,sub
,sub_len
,count
,&out_len
);
1169 if (new_s
== NULL
) {
1173 if (out_len
== -1) {
1174 /* we're returning another reference to the input string */
1175 new = PyTuple_GetItem(args
, 0);
1179 new = PyString_FromStringAndSize(new_s
, out_len
);
1186 /* List of functions defined in the module */
1190 {"atof", strop_atof
, METH_VARARGS
, atof__doc__
},
1191 {"atoi", strop_atoi
, METH_VARARGS
, atoi__doc__
},
1192 {"atol", strop_atol
, METH_VARARGS
, atol__doc__
},
1193 {"capitalize", strop_capitalize
, METH_OLDARGS
, capitalize__doc__
},
1194 {"count", strop_count
, METH_VARARGS
, count__doc__
},
1195 {"expandtabs", strop_expandtabs
, METH_VARARGS
, expandtabs__doc__
},
1196 {"find", strop_find
, METH_VARARGS
, find__doc__
},
1197 {"join", strop_joinfields
, METH_VARARGS
, joinfields__doc__
},
1198 {"joinfields", strop_joinfields
, METH_VARARGS
, joinfields__doc__
},
1199 {"lstrip", strop_lstrip
, METH_OLDARGS
, lstrip__doc__
},
1200 {"lower", strop_lower
, METH_OLDARGS
, lower__doc__
},
1201 {"maketrans", strop_maketrans
, METH_VARARGS
, maketrans__doc__
},
1202 {"replace", strop_replace
, METH_VARARGS
, replace__doc__
},
1203 {"rfind", strop_rfind
, METH_VARARGS
, rfind__doc__
},
1204 {"rstrip", strop_rstrip
, METH_OLDARGS
, rstrip__doc__
},
1205 {"split", strop_splitfields
, METH_VARARGS
, splitfields__doc__
},
1206 {"splitfields", strop_splitfields
, METH_VARARGS
, splitfields__doc__
},
1207 {"strip", strop_strip
, METH_OLDARGS
, strip__doc__
},
1208 {"swapcase", strop_swapcase
, METH_OLDARGS
, swapcase__doc__
},
1209 {"translate", strop_translate
, METH_VARARGS
, translate__doc__
},
1210 {"upper", strop_upper
, METH_OLDARGS
, upper__doc__
},
1211 {NULL
, NULL
} /* sentinel */
1218 PyObject
*m
, *d
, *s
;
1221 m
= Py_InitModule4("strop", strop_methods
, strop_module__doc__
,
1222 (PyObject
*)NULL
, PYTHON_API_VERSION
);
1223 d
= PyModule_GetDict(m
);
1225 /* Create 'whitespace' object */
1227 for (c
= 0; c
< 256; c
++) {
1231 s
= PyString_FromStringAndSize(buf
, n
);
1233 PyDict_SetItemString(d
, "whitespace", s
);
1236 /* Create 'lowercase' object */
1238 for (c
= 0; c
< 256; c
++) {
1242 s
= PyString_FromStringAndSize(buf
, n
);
1244 PyDict_SetItemString(d
, "lowercase", s
);
1248 /* Create 'uppercase' object */
1250 for (c
= 0; c
< 256; c
++) {
1254 s
= PyString_FromStringAndSize(buf
, n
);
1256 PyDict_SetItemString(d
, "uppercase", s
);