From 1ee77d9b71dab3b42b3c00760216cc4955a3cfeb Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Thu, 10 May 2001 01:23:39 +0000 Subject: Guido has Spoken. Restore strop.replace()'s treatment of a 0 count as meaning infinity -- but at least warn about it in the code! I pissed away a couple hours on this today, and don't wish the same on the next in line. Bugfix candidate. --- Lib/test/test_strop.py | 4 +++- Modules/stropmodule.c | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_strop.py b/Lib/test/test_strop.py index de7a795..9130088 100644 --- a/Lib/test/test_strop.py +++ b/Lib/test/test_strop.py @@ -77,7 +77,9 @@ test('replace', 'one!two!three!', 'one@two!three!', '!', '@', 1) test('replace', 'one!two!three!', 'one@two@three!', '!', '@', 2) test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 3) test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 4) -test('replace', 'one!two!three!', 'one!two!three!', '!', '@', 0) +# CAUTION: a replace count of 0 means infinity only to strop, not to the +# string .replace() method or to the string.replace() function. +test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 0) test('replace', 'one!two!three!', 'one@two@three@', '!', '@') test('replace', 'one!two!three!', 'one!two!three!', 'x', '@') test('replace', 'one!two!three!', 'one!two!three!', 'x', '@', 2) diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c index aa9cdc7..312e0dc 100644 --- a/Modules/stropmodule.c +++ b/Modules/stropmodule.c @@ -1132,6 +1132,12 @@ strop_replace(PyObject *self, PyObject *args) PyErr_SetString(PyExc_ValueError, "empty pattern string"); return NULL; } + /* CAUTION: strop treats a replace count of 0 as infinity, unlke + * current (2.1) string.py and string methods. Preserve this for + * ... well, hard to say for what . + */ + if (count == 0) + count = -1; new_s = mymemreplace(str,len,pat,pat_len,sub,sub_len,count,&out_len); if (new_s == NULL) { PyErr_NoMemory(); -- cgit v0.12