unified join(fields), split(fields)

This commit is contained in:
Guido van Rossum 1995-05-03 17:40:23 +00:00
parent 953dc1a079
commit 009e79bf02
1 changed files with 20 additions and 12 deletions

View File

@ -35,16 +35,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static object * static object *
strop_split(self, args) split_whitespace(s, len)
object *self; /* Not used */
object *args;
{
int len, i, j, err;
char *s; char *s;
int len;
{
int i, j, err;
object *list, *item; object *list, *item;
if (!getargs(args, "s#", &s, &len))
return NULL;
list = newlistobject(0); list = newlistobject(0);
if (list == NULL) if (list == NULL)
return NULL; return NULL;
@ -86,8 +83,12 @@ strop_splitfields(self, args)
char *s, *sub; char *s, *sub;
object *list, *item; object *list, *item;
if (!getargs(args, "(s#s#)", &s, &len, &sub, &n)) sub = NULL;
n = 0;
if (!newgetargs(args, "s#|z#", &s, &len, &sub, &n))
return NULL; return NULL;
if (sub == NULL)
return split_whitespace(s, len);
if (n == 0) { if (n == 0) {
err_setstr(ValueError, "empty separator"); err_setstr(ValueError, "empty separator");
return NULL; return NULL;
@ -138,8 +139,14 @@ strop_joinfields(self, args)
char *sep, *p; char *sep, *p;
int seplen, seqlen, reslen, itemlen, i; int seplen, seqlen, reslen, itemlen, i;
if (!getargs(args, "(Os#)", &seq, &sep, &seplen)) sep = NULL;
seplen = 0;
if (!newgetargs(args, "O|s#", &seq, &sep, &seplen))
return NULL; return NULL;
if (sep == NULL) {
sep = " ";
seplen = 1;
}
if (is_listobject(seq)) { if (is_listobject(seq)) {
getitem = getlistitem; getitem = getlistitem;
seqlen = getlistsize(seq); seqlen = getlistsize(seq);
@ -503,11 +510,12 @@ static struct methodlist strop_methods[] = {
{"atoi", strop_atoi}, {"atoi", strop_atoi},
{"atol", strop_atol}, {"atol", strop_atol},
{"find", strop_find}, {"find", strop_find},
{"joinfields", strop_joinfields}, {"join", strop_joinfields, 1},
{"joinfields", strop_joinfields, 1},
{"lower", strop_lower}, {"lower", strop_lower},
{"rfind", strop_rfind}, {"rfind", strop_rfind},
{"split", strop_split}, {"split", strop_splitfields, 1},
{"splitfields", strop_splitfields}, {"splitfields", strop_splitfields, 1},
{"strip", strop_strip}, {"strip", strop_strip},
{"swapcase", strop_swapcase}, {"swapcase", strop_swapcase},
{"upper", strop_upper}, {"upper", strop_upper},