From 4fb4c6d4b39d2e9357d6050286087b40d116193c Mon Sep 17 00:00:00 2001 From: jim winstead Date: Sat, 5 Jan 2002 23:49:58 +0000 Subject: [PATCH] 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.) --- ext/standard/string.c | 6 ++++-- ext/standard/tests/strings/wordwrap.phpt | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) 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 = <<