From: jim winstead Date: Sat, 5 Jan 2002 23:49:58 +0000 (+0000) Subject: More tweaking of wordwrap() with the cut parameter set. It was being a X-Git-Tag: PRE_ISSET_PATCH~278 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4fb4c6d4b39d2e9357d6050286087b40d116193c;p=php 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.) --- diff --git a/ext/standard/string.c b/ext/standard/string.c index 3149130089..39d41b9531 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -696,8 +696,10 @@ PHP_FUNCTION(wordwrap) 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); diff --git a/ext/standard/tests/strings/wordwrap.phpt b/ext/standard/tests/strings/wordwrap.phpt index 7fa85f40f8..ba2f766518 100644 --- a/ext/standard/tests/strings/wordwrap.phpt +++ b/ext/standard/tests/strings/wordwrap.phpt @@ -20,10 +20,13 @@ $tests = <<