From bcad90fe3294823c4995828b94e37924da70edd6 Mon Sep 17 00:00:00 2001 From: fidian Date: Thu, 12 Oct 2000 16:57:01 +0000 Subject: [PATCH] Modified sqWordWrap again, it also now works with lines like '>' git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@794 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/strings.php | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/functions/strings.php b/functions/strings.php index fa1d84f9..40f5f15b 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -49,7 +49,7 @@ // you do character translation. // Specifically, ' comes up as 5 characters instead of 1. function sqWordWrap(&$line, $wrap) { - preg_match("/^([\s>]*)([^\s>].*)$/", $line, $regs); + preg_match("/^([\s>]*)([^\s>].*)?$/", $line, $regs); $beginning_spaces = $regs[1]; $regs[2] .= "\n"; $words = explode(" ", $regs[2]); @@ -57,33 +57,28 @@ $i = 0; $line = $beginning_spaces; - if (count($words) > 1) { - while ($i < count($words)) { - // Force one word to be on a line (minimum) - $line .= $words[$i]; - $line_len = strlen($beginning_spaces) + strlen($words[$i]) + - strlen($words[$i + 1]) + 2; - $i ++; + while ($i < count($words)) { + // Force one word to be on a line (minimum) + $line .= $words[$i]; + $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; - } + // 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; + } - // Skip spaces if they are the first thing on a continued line - while (!$words[$i] && $i < count($words)) - { - $i ++; - } + // 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"; - } + if ($i < count($words)) { + $line .= "\n$beginning_spaces"; } - } else { - $line .= $words[0]; } } -- 2.25.1