/**
  * OVERWRITE:
  * Appends the search word number as a suffix to the CSS span class.
  * 
  * Marks up the search words from $this->sWarr in the $str with a color.
  *
  * @param	string		Text in which to find and mark up search words. This text is assumed to be UTF-8 like the search words internally is.
  * @return	string		Processed content.
  */
 function markupSWpartsOfString($str)
 {
     // Init:
     $str = str_replace(' ', ' ', t3lib_parsehtml::bidir_htmlspecialchars($str, -1));
     $str = preg_replace('/\\s\\s+/', ' ', $str);
     $swForReg = array();
     // Prepare search words for regex:
     foreach ($this->sWArr as $d) {
         $swForReg[] = preg_quote($d['sword'], '/');
     }
     $regExString = '(' . implode('|', $swForReg) . ')';
     // Split and combine:
     $parts = preg_split('/' . $regExString . '/i', ' ' . $str . ' ', 20000, PREG_SPLIT_DELIM_CAPTURE);
     // debug($parts,$regExString);
     // Constants:
     $summaryMax = 300;
     $postPreLgd = 60;
     $postPreLgd_offset = 5;
     $divider = ' ... ';
     $occurencies = (count($parts) - 1) / 2;
     if ($occurencies) {
         $postPreLgd = t3lib_div::intInRange($summaryMax / $occurencies, $postPreLgd, $summaryMax / 2);
     }
     // Variable:
     $summaryLgd = 0;
     $output = array();
     // Shorten in-between strings:
     //reset
     $this->sword_number = 1;
     foreach ($parts as $k => $strP) {
         if ($k % 2 == 0) {
             // Find length of the summary part:
             $strLen = $GLOBALS['TSFE']->csConvObj->strlen('utf-8', $parts[$k]);
             $output[$k] = $parts[$k];
             // Possibly shorten string:
             if (!$k) {
                 // First entry at all (only cropped on the frontside)
                 if ($strLen > $postPreLgd) {
                     $output[$k] = $divider . ereg_replace('^[^[:space:]]+[[:space:]]', '', $GLOBALS['TSFE']->csConvObj->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
                 }
             } elseif ($summaryLgd > $summaryMax || !isset($parts[$k + 1])) {
                 // In case summary length is exceed OR if there are no more entries at all:
                 if ($strLen > $postPreLgd) {
                     $output[$k] = ereg_replace('[[:space:]][^[:space:]]+$', '', $GLOBALS['TSFE']->csConvObj->crop('utf-8', $parts[$k], $postPreLgd - $postPreLgd_offset)) . $divider;
                 }
             } else {
                 // In-between search words:
                 if ($strLen > $postPreLgd * 2) {
                     $output[$k] = ereg_replace('[[:space:]][^[:space:]]+$', '', $GLOBALS['TSFE']->csConvObj->crop('utf-8', $parts[$k], $postPreLgd - $postPreLgd_offset)) . $divider . ereg_replace('^[^[:space:]]+[[:space:]]', '', $GLOBALS['TSFE']->csConvObj->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
                 }
             }
             $summaryLgd += $GLOBALS['TSFE']->csConvObj->strlen('utf-8', $output[$k]);
             // Protect output:
             $output[$k] = htmlspecialchars($output[$k]);
             // If summary lgd is exceed, break the process:
             if ($summaryLgd > $summaryMax) {
                 break;
             }
         } else {
             $summaryLgd += $GLOBALS['TSFE']->csConvObj->strlen('utf-8', $strP);
             //start OVERWRITE
             $output[$k] = '<strong class="tx-psmhighlight-sword-' . $this->swords[$GLOBALS['TSFE']->csConvObj->conv_case('utf-8', $parts[$k], 'toLower')] . '">' . htmlspecialchars($parts[$k]) . '</strong>';
             //end OVERWRITE
         }
     }
     // Return result:
     return implode('', $output);
 }