From: fidian Date: Tue, 10 Oct 2000 17:46:57 +0000 (+0000) Subject: Minor bugfixes: X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=45f6dd68fe742e12c488dbf1d044593aa0eac98a Minor bugfixes: - Single word lines would have been wrong (count($words) <= 1) - $beginning_spaces doubled on first line that was wrapped - Skips leading spaces on wrapped lines, preserving them on the first line git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@788 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/strings.php b/functions/strings.php index 94e7d051..5d450134 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -49,10 +49,9 @@ // you do character translation. // Specifically, ' comes up as 5 characters instead of 1. function sqWordWrap(&$line, $wrap) { - preg_match("/^(\s|>)+/", $line, $regs); - $beginning_spaces = $regs[0]; - - $words = explode(" ", $line); + preg_match("/^([\s>]+)([^\s>].*)/", $line, $regs); + $beginning_spaces = $regs[1]; + $words = explode(" ", $regs[2]); $i = 0; $line = $beginning_spaces; @@ -63,17 +62,26 @@ $line_len = strlen($beginning_spaces) + strlen($words[$i]) + strlen($words[$i + 1]) + 2; $i ++; + + // Add more words (as long as they fit) while ($line_len < $wrap && $i < count($words)) { $line .= $words[$i] . ' '; $i++; $line_len += strlen($words[$i]) + 1; } - if ($i < count($words)) { // If there's more to do, worry about it + + // Skip spaces if they are the first thing on a continued line + while (!$words[$i] && $i < count($words)) + { + $i ++; + } + + if ($i < count($words)) { $line .= "\n$beginning_spaces"; } } } else { - $line = $words[0]; + $line .= $words[0]; } }