cvs: php4 /ext/standard string.c /ext/standard/tests/strings wordwrap.phpt

From: Date: Sat, 05 Jan 2002 23:49:58 +0000
Subject: cvs: php4 /ext/standard string.c /ext/standard/tests/strings wordwrap.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-8958@lists.php.net to get a copy of this message
jimw Sat Jan 5 18:49:58 2002 EDT Modified files: /php4/ext/standard string.c /php4/ext/standard/tests/strings wordwrap.phpt Log: More tweaking of wordwrap() with the cut parameter set. It was being a little too aggressive and cutting words without breaking at spaces first. (A couple of tests were incorrect.) Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.260 php4/ext/standard/string.c:1.261 --- php4/ext/standard/string.c:1.260 Sat Jan 5 15:46:41 2002 +++ php4/ext/standard/string.c Sat Jan 5 18:49:57 2002 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.260 2002/01/05 20:46:41 jimw Exp $ */ +/* $Id: string.c,v 1.261 2002/01/05 23:49:57 jimw Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -696,8 +696,10 @@ lastspace = current; } /* if we are cutting, and we've accumulated enough - * characters, copy and insert a break. */ - else if (current - laststart >= linelength && docut) { + * characters, and we haven't see a space for this line, + * copy and insert a break. */ + else if (current - laststart >= linelength + && docut && laststart >= lastspace) { memcpy(newtext+newtextlen, text+laststart, current-laststart); newtextlen += current - laststart; memcpy(newtext+newtextlen, breakchar, breakcharlen); Index: php4/ext/standard/tests/strings/wordwrap.phpt diff -u php4/ext/standard/tests/strings/wordwrap.phpt:1.2 php4/ext/standard/tests/strings/wordwrap.phpt:1.3 --- php4/ext/standard/tests/strings/wordwrap.phpt:1.2 Sat Jan 5 15:46:43 2002 +++ php4/ext/standard/tests/strings/wordwrap.phpt Sat Jan 5 18:49:58 2002 @@ -20,10 +20,13 @@ "123ab123ab123" === wordwrap("123ab123ab123", 3, "ab", 1) "123ab123ab123" === wordwrap("123ab123ab123", 5, "ab", 1) "123ab 12ab3ab123" === wordwrap("123 123ab123", 3, "ab", 1) -"123 ab123ab123" === wordwrap("123 123ab123", 5, "ab", 1) +"123 ab123ab123" === wordwrap("123 123ab123", 5, "ab", 1) "123 123ab 123" === wordwrap("123 123 123", 8, "ab", 1) -"123 123ab45 123" === wordwrap("123 12345 123", 8, "ab", 1) +"123 ab12345 ab123" === wordwrap("123 12345 123", 8, "ab", 1) "1ab2ab3ab4" === wordwrap("1234", 1, "ab", 1) + +"12345|12345|67890" === wordwrap("12345 1234567890", 5, "|", 1) + TESTS; include('../../../../tests/quicktester.inc');

« previous php.cvs (#8958) next »