From: Fredrik Lundh Date: Tue, 30 May 2006 17:39:58 +0000 (+0000) Subject: changed count to return 0 for slices outside the source string X-Git-Tag: v2.5b1~328 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9e9ef9fa5a789f02a04c08998c4b74af9686e43a;p=thirdparty%2FPython%2Fcpython.git changed count to return 0 for slices outside the source string --- diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index c2e0875b768b..8962c1f07a73 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -115,7 +115,8 @@ class CommonTest(unittest.TestCase): self.checkequal(2, 'aaa', 'count', 'a', 0, -1) self.checkequal(0, 'aaa', 'count', 'a', 0, -10) self.checkequal(3, 'aaa', 'count', '', 1) - self.checkequal(1, 'aaa', 'count', '', 10) + self.checkequal(1, 'aaa', 'count', '', 3) + self.checkequal(0, 'aaa', 'count', '', 10) self.checkequal(2, 'aaa', 'count', '', -1) self.checkequal(4, 'aaa', 'count', '', -10) diff --git a/Objects/stringlib/count.h b/Objects/stringlib/count.h index 84a852f52e49..367a15c51a5d 100644 --- a/Objects/stringlib/count.h +++ b/Objects/stringlib/count.h @@ -15,7 +15,7 @@ stringlib_count(const STRINGLIB_CHAR* str, Py_ssize_t str_len, if (sub_len == 0) { if (str_len < 0) - return 1; /* start >= len(str) */ + return 0; /* start > len(str) */ return str_len + 1; }