]> granicus.if.org Git - php/commitdiff
More tweaking of wordwrap() with the cut parameter set. It was being a
authorjim winstead <jimw@php.net>
Sat, 5 Jan 2002 23:49:58 +0000 (23:49 +0000)
committerjim winstead <jimw@php.net>
Sat, 5 Jan 2002 23:49:58 +0000 (23:49 +0000)
little too aggressive and cutting words without breaking at spaces
first. (A couple of tests were incorrect.)

ext/standard/string.c
ext/standard/tests/strings/wordwrap.phpt

index 314913008906797b7a47984ca52d705703fc3d6a..39d41b95315f990bdee279fe19868f4beaf96225 100644 (file)
@@ -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);
index 7fa85f40f84aa2f94b5bd3d4df37bf209309cf09..ba2f76651806694343f9a66a7b736185cc80c1f0 100644 (file)
@@ -20,10 +20,13 @@ $tests = <<<TESTS
 "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');