* @return string the wrapped text
*/
function &sqBodyWrap (&$body, $wrap) {
- //sm_print_r($body);
//check for ctype support, and fake it if it doesn't exist
if (!function_exists('ctype_space')) {
function ctype_space ($string) {
// skip over any spaces interleaved among the cite markers
while (($pos < $length) && ($body{$pos} == ' ')) {
-
+
$pos++;
-
+
}
if ($pos >= $length) {
break;
$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
$pos++;
}
+
// if this is a short line then just append it and continue outer loop
if (($outStringCol + $nextNewline - $pos) <= ($wrap - $citeLevel - 1) ) {
// if this is the final line in the input string then include
$nextNewline++;
}
- if (($nextNewline < $length && $body{$nextNewline} == "\n") &&
- isset($lastRealChar)) {
+ // trim trailing spaces
+ $lastRealChar = $nextNewline;
+ while (($lastRealChar > $pos && $lastRealChar < $length) && (ctype_space ($body{$lastRealChar}))) {
+ $lastRealChar--;
+ }
- // trim trailing spaces
- $lastRealChar = $nextNewline;
- 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)) {
//check the first word:
- $mypos = $nextNewline+1;
- while (($mypos < $length) && ($body{$mypos} == '>')) {
- $mypos++;
-
- // skip over any spaces interleaved among the cite markers
- while (($mypos < $length) && ($body{$mypos} == ' ')) {
-
+ $mypos = $nextNewline+1;
+ while (($mypos < $length) && ($body{$mypos} == '>')) {
+ $mypos++;
+ // skip over any spaces interleaved among the cite markers
+ 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 ($firstword && ($firstword{0} == '-' ||
+ }
+*/
+
+ $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; //break 2;
- }
- }
-
+ $outString .= substr($body,$pos,($lastRealChar - $pos+1));
+ $outStringCol += ($lastRealChar - $pos);
+ sqMakeNewLine($outString,$citeLevel,$outStringCol);
+ $nextNewline++;
+ $pos = $nextNewline;
+ $outStringCol--;
+ continue;
+ }
- // trim trailing spaces
- $lastRealChar = $nextNewline;
- while (($lastRealChar > $pos && $lastRealChar < $length) && (ctype_space ($body{$lastRealChar}))) {
- $lastRealChar--;
}
+
$outString .= substr ($body, $pos, ($lastRealChar - $pos + 1));
$outStringCol += ($lastRealChar - $pos);
$pos = $nextNewline + 1;
continue;
}
+
$eol = $pos + $wrap - $citeLevel - $outStringCol;
// eol is the tentative end of line.
// look backwards for there for a whitespace to break at.
$body_part_entity->header->encoding);
if ($type1 == 'html') {
$bodypart = str_replace("\n", ' ', $bodypart);
- $bodypart = preg_replace(array('/<p>/i','/<div><\/div>/i','/<br\s*(\/)*>/i','/<\/?div>/i'), "\n", $bodypart);
-
+ $bodypart = preg_replace(array('/<\/?p>/i','/<div><\/div>/i','/<br\s*(\/)*>/i','/<\/?div>/i'), "\n", $bodypart);
$bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
$bodypart = strip_tags($bodypart);
}