Adding FIXME to comment
[squirrelmail.git] / functions / strings.php
index 1be033e9a1c4e22d25b1bffc0f85fa5a64d8c363..242a29b967e45b34d8f390a63f15f7096b6e197b 100644 (file)
@@ -145,7 +145,9 @@ function &sqBodyWrap (&$body, $wrap) {
 
            // skip over any spaces interleaved among the cite markers
            while (($pos < $length) && ($body{$pos} == ' ')) {
+
                $pos++;
+
            }
            if ($pos >= $length) {
                break;
@@ -155,7 +157,7 @@ function &sqBodyWrap (&$body, $wrap) {
        // special case: if this is a blank line then maintain it
        // (i.e. try to preserve original paragraph breaks)
        // unless they occur at the very beginning of the text
-       if (($body{$pos} == "\n") && (strlen($outString) != 0)) {
+       if (($body{$pos} == "\n" ) && (strlen($outString) != 0)) {
            $outStringLast = $outString{strlen($outString) - 1};
            if ($outStringLast != "\n") {
                $outString .= "\n";
@@ -207,7 +209,10 @@ function &sqBodyWrap (&$body, $wrap) {
            $pos = $nextNewline + 1;
            continue;
        }
-
+       /**
+        * Set this to false to stop appending short strings to previous lines
+        */
+       $smartwrap = true;
        // inner loop, (obviously) handles wrapping up to
        // the next newline
        while ($pos < $nextNewline) {
@@ -215,20 +220,60 @@ function &sqBodyWrap (&$body, $wrap) {
            while (($pos < $nextNewline) && (ctype_space ($body{$pos}))) {
                $pos++;
            }
-
            // if this is a short line then just append it and continue outer loop
-           if (($outStringCol + $nextNewline - $pos) <= ($wrap - $citeLevel - 1)) {
+           if (($outStringCol + $nextNewline - $pos) <= ($wrap - $citeLevel - 1) ) {
                // if this is the final line in the input string then include
                // any trailing newlines
+               //      echo substr($body,$pos,$wrap). "<br />";
                if (($nextNewline + 1 == $length) && ($body{$nextNewline} == "\n")) {
                    $nextNewline++;
                }
 
                // trim trailing spaces
                $lastRealChar = $nextNewline;
-               while (($lastRealChar > $pos) && (ctype_space ($body{$lastRealChar}))) {
+               while (($lastRealChar > $pos && $lastRealChar < $length) && (ctype_space ($body{$lastRealChar}))) {
                    $lastRealChar--;
                }
+               // decide if appending the short string is what we want
+               if (($nextNewline < $length && $body{$nextNewline} == "\n") &&
+                     isset($lastRealChar)) {
+                   $mypos = $pos;
+                   //check the first word:
+                   while (($mypos < $length) && ($body{$mypos} == '>')) {
+                       $mypos++;
+                       // skip over any spaces interleaved among the cite markers
+                       $oldpos = $mypos;
+                       while (($mypos < $length) && ($body{$mypos} == ' ')) {
+                           $mypos++;
+                       }
+                   }
+/*
+                     $ldnspacecnt = 0;
+                     if ($mypos == $nextNewline+1) {
+                        while (($mypos < $length) && ($body{$mypos} == ' ')) {
+                         $ldnspacecnt++;
+                        }
+                     }
+*/
+
+                   $firstword = substr($body,$mypos,strpos($body,' ',$mypos) - $mypos);
+                   //if ($dowrap || $ldnspacecnt > 1 || ($firstword && (
+                   if (!$smartwrap || $firstword && (
+                                        $firstword{0} == '-' ||
+                                        $firstword{0} == '+' ||
+                                        $firstword{0} == '*' ||
+                                        $firstword{0} == strtoupper($firstword{0}) ||
+                                        strpos($firstword,':'))) {
+                        $outString .= substr($body,$pos,($lastRealChar - $pos+1));
+                        $outStringCol += ($lastRealChar - $pos);
+                        sqMakeNewLine($outString,$citeLevel,$outStringCol);
+                        $nextNewline++;
+                        $pos = $nextNewline;
+                        $outStringCol--;
+                        continue;
+                   }
+
+               }
 
                $outString .= substr ($body, $pos, ($lastRealChar - $pos + 1));
                $outStringCol += ($lastRealChar - $pos);
@@ -243,7 +288,7 @@ function &sqBodyWrap (&$body, $wrap) {
            // our current line is already too long, break immediately
            // and restart outer loop
            if ($eol <= $pos) {
-               sqMakeNewLine ($outString, $citeLeve, $outStringCol);
+               sqMakeNewLine ($outString, $citeLevel, $outStringCol);
                continue;
            }