Swaps out spaces and tabs for HTML indentation. Not needed if
the code is in a pre block...

@param  string $result The source to indent (reference!)
@since  1.0.0
968458
protected function indent(&$result) {
        /// Replace tabs with the correct number of spaces
        if (false !== strpos($result, "\t")) {
            $lines = explode("\n", $result);
            $result = null;//Save memory while we process the lines individually
            $tab_width = $this->get_real_tab_width();
            $tab_string = '&nbsp;' . str_repeat(' ', $tab_width);

            for ($key = 0, $n = count($lines); $key < $n; $key++) {
                $line = $lines[$key];
                if (false === strpos($line, "\t")) {
                    continue;
                }

                $pos = 0;
                $length = strlen($line);
                $lines[$key] = ''; // reduce memory

                $IN_TAG = false;
                for ($i = 0; $i < $length; ++$i) {
                    $char = $line[$i];
                    // Simple engine to work out whether we're in a tag.
                    // If we are we modify $pos. This is so we ignore HTML
                    // in the line and only workout the tab replacement
                    // via the actual content of the string
                    // This test could be improved to include strings in the
                    // html so that < or > would be allowed in user's styles
                    // (e.g. quotes: '<' '>'; or similar)
                    if ($IN_TAG) {
                        if ('>' == $char) {
                            $IN_TAG = false;
                        }
                        $lines[$key] .= $char;
                    } elseif ('<' == $char) {
                        $IN_TAG = true;
                        $lines[$key] .= '<';
                    } elseif ('&' == $char) {
                        $substr = substr($line, $i + 3, 5);
                        $posi = strpos($substr, ';');
                        if (false === $posi) {
                            ++$pos;
                        } else {
                            $pos -= $posi+2;
                        }
                        $lines[$key] .= $char;
                    } elseif ("\t" == $char) {
                        $str = '';
                        // OPTIMISE - move $strs out. Make an array:
                        // $tabs = array(
                        //  1 => '&nbsp;',
                        //  2 => '&nbsp; ',
                        //  3 => '&nbsp; &nbsp;' etc etc
                        // to use instead of building a string every time
                        $tab_end_width = $tab_width - ($pos % $tab_width); //Moved out of the look as it doesn't change within the loop
                        if (($pos & 1) || 1 == $tab_end_width) {
                            $str .= substr($tab_string, 6, $tab_end_width);
                        } else {
                            $str .= substr($tab_string, 0, $tab_end_width+5);
                        }
                        $lines[$key] .= $str;
                        $pos += $tab_end_width;

                        if (false === strpos($line, "\t", $i + 1)) {
                            $lines[$key] .= substr($line, $i + 1);
                            break;
                        }
                    } elseif (0 == $pos && ' ' == $char) {
                        $lines[$key] .= '&nbsp;';
                        ++$pos;
                    } else {
                        $lines[$key] .= $char;
                        ++$pos;
                    }
                }
            }
            $result = implode("\n", $lines);
            unset($lines);//We don't need the lines separated beyond this --- free them!
        }
        // Other whitespace
        // BenBE: Fix to reduce the number of replacements to be done
        $result = preg_replace('/^ /m', '&nbsp;', $result);
        $result = str_replace('  ', ' &nbsp;', $result);

        if ($this->line_numbers == GESHI_NO_LINE_NUMBERS && $this->header_type != GESHI_HEADER_PRE_TABLE) {
            if ($this->line_ending === null) {
                $result = nl2br($result);
            } else {
                $result = str_replace("\n", $this->line_ending, $result);
            }
        }
    }
907659
public function fixResult(&$result, $domain)
    {
        // Add usual fields
        $result['regrinfo']['domain']['name'] = $domain;

        // Check if nameservers exist
        if (!isset($result['regrinfo']['registered'])) {
            if (function_exists('checkdnsrr') && checkdnsrr($domain, 'NS')) {
                $result['regrinfo']['registered'] = 'yes';
            } else {
                $result['regrinfo']['registered'] = 'unknown';
            }
        }

        // Normalize nameserver fields
        if (isset($result['regrinfo']['domain']['nserver'])) {
            if (!is_array($result['regrinfo']['domain']['nserver'])) {
                unset($result['regrinfo']['domain']['nserver']);
            } else {
                $result['regrinfo']['domain']['nserver'] = $this->fixNameServer($result['regrinfo']['domain']['nserver']);
            }
        }
    }
1108520
private function addCurrencySymbol($result)
    {
        $format = ($this->config['symbol_position'] === 'left')
            ? '%1$s %2$s'
            : '%2$s %1$s';

        return sprintf(
            $format,
            $this->context->getCurrencySymbol($this->config),
            $result
        );
    }
747051
private function transformResult($result)
    {
        if ($this->actualDriver() === self::DRIVER_PREDIS && $result instanceof Status) {
            $result = $result->getPayload() === 'OK';
        }
        return $result;
    }
182804
public function prepareResponse($result)
    {
        $response = ['header' => null, 'content' => null];
        $d = "\r\n\r\n"; // Headers and content delimiter

        if (is_string($result) && strpos($result, $d) !== false) {
            list($header, $content) = explode($d, $result, 2);
            if (stripos($header, '100 Continue') !== false && strpos($content, $d) !== false) {
                list($header, $content) = explode($d, $content, 2);
            }
            $response['header'] = $header;
            $response['content'] = htmlentities($content);
        }

        return $response;
    }
1223902
private function getFormattedResults(&$results) {
    return implode('', array(
        $this->getReportInfo($results),
        $this->getPaginationInfo($results),
        $this->getProfileInformation($results),
        $this->getQueryParameters($results),
        $this->getColumnHeaders($results),
        $this->getTotalsForAllResults($results),
        $this->getRows($results)
    ));
    
  }
716241
public function paintText($text, Definition $definition, TestResult $result)
    {
        $regex = $this->patternTransformer->transformPatternToRegex($definition->getPattern());
        $style = $this->resultConverter->convertResultToString($result);
        $paramStyle = $style . '_param';

        // If it's just a string - skip
        if ('/' !== substr($regex, 0, 1)) {
            return $text;
        }

        // Find arguments with offsets
        $matches = array();
        preg_match($regex, $text, $matches, PREG_OFFSET_CAPTURE);
        array_shift($matches);

        // Replace arguments with colorized ones
        $shift = 0;
        $lastReplacementPosition = 0;
        foreach ($matches as $key => $match) {
            if (!is_numeric($key) || -1 === $match[1] || false !== strpos($match[0], '<')) {
                continue;
            }

            $offset = $match[1] + $shift;
            $value = $match[0];

            // Skip inner matches
            if ($lastReplacementPosition > $offset) {
                continue;
            }
            $lastReplacementPosition = $offset + strlen($value);

            $begin = substr($text, 0, $offset);
            $end = substr($text, $lastReplacementPosition);
            $format = "{-$style}{+$paramStyle}%s{-$paramStyle}{+$style}";
            $text = sprintf("%s{$format}%s", $begin, $value, $end);

            // Keep track of how many extra characters are added
            $shift += strlen($format) - 2;
            $lastReplacementPosition += strlen($format) - 2;
        }

        // Replace "<", ">" with colorized ones
        $text = preg_replace(
            '/(<[^>]+>)/',
            "{-$style}{+$paramStyle}\$1{-$paramStyle}{+$style}",
            $text
        );

        return $text;
    }
1128847
private function process(IdentResult &$result)
    {
        if (isset($result->person)) {
            foreach ($result->person as $p) {
                $attachments = $p->attachments;
                if (!empty($attachments)) {
                    foreach ($attachments as $attachment) {
                        $this->initMediaResource($attachment);
                    }
                }
            }
        }
    }
1298025
protected function _decorateResults($result)
    {
        $decorator = $this->_decoratorClass();
        foreach ($this->_mapReduce as $functions) {
            $result = new MapReduce($result, $functions['mapper'], $functions['reducer']);
        }

        if (!empty($this->_mapReduce)) {
            $result = new $decorator($result);
        }

        foreach ($this->_formatters as $formatter) {
            $result = $formatter($result);
        }

        if (!empty($this->_formatters) && !($result instanceof $decorator)) {
            $result = new $decorator($result);
        }

        return $result;
    }
473735
public function encode($result)
    {
        if ('form' == $this->type) {
            array_walk_recursive($result[0], array($this, 'utf8'));
            
            $response = new SfResponse("<html><body><textarea>".json_encode($result[0])."</textarea></body></html>");            
            $response->headers->set('Content-Type', 'text/html');
            
            return $response;
        } else {
            if ($this->responseEncode){
                // @todo: check utf8 config option from bundle
                array_walk_recursive($result, array($this, 'utf8'));
            }

            $response = new SfResponse(json_encode($result));            
            $response->headers->set('Content-Type', 'application/json');
            
            return $response;
        }
    }
765990
function indent($str, $output = true) {
    if ($this->parser->isStartTag) {
      $this->indent .= $str;
      if ($output) {
        $this->out($str, true);
      }
    } else {
      $this->indent = substr($this->indent, 0, -strlen($str));
    }
  }
981620
protected function renameResult(array &$result, $old, $new)
    {

        // Check to see if the old item is there
        if (isset($result[$old])) {
            $result[$new] = $result[$old];
            unset($result[$old]);
        }
    }
530496
public function convertArticleLayout($result) {
        if (isset($result->chapters)) {
            $result->chapters = array_map(
                array($this, '_convertChapterLayout'),
                $result->chapters->toArray()
            );
        }
    }
916616
protected function printFooter(\PHPUnit\Framework\TestResult $result): void
    {
        parent::printFooter($result);

        $this->writeNewLine();
        $this->write("Randomized with seed: {$this->seed}");
        $this->writeNewLine();
    }
854537
public function dump($result = null)
	{
		static $keywords1 = 'SELECT|(?:ON\s+DUPLICATE\s+KEY)?UPDATE|INSERT(?:\s+INTO)?|REPLACE(?:\s+INTO)?|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|LIMIT|OFFSET|FETCH\s+NEXT|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN|TRUNCATE|START\s+TRANSACTION|BEGIN|COMMIT|ROLLBACK(?:\s+TO\s+SAVEPOINT)?|(?:RELEASE\s+)?SAVEPOINT';
		static $keywords2 = 'ALL|DISTINCT|DISTINCTROW|IGNORE|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|LIKE|RLIKE|REGEXP|TRUE|FALSE';

		// insert new lines
		$sql = " $result ";
		$sql = \preg_replace("#(?<=[\\s,(])($keywords1)(?=[\\s,)])#i", "\n\$1", $sql);
		// reduce spaces
		$sql = \preg_replace('#[ \t]{2,}#', ' ', $sql);
		$sql = \wordwrap($sql, 100);
		$sql = \preg_replace("#([ \t]*\r?\n){2,}#", "\n", $sql);
		// syntax highlight
		$highlighter = "#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is";

		$sql = \htmlspecialchars($sql);
		$sql = \preg_replace_callback($highlighter, function ($m) {
			if (!empty($m[1])) { // comment
				return '<em style="color:gray">' . $m[1] . '</em>';
			}

			if (!empty($m[2])) { // error
				return '<strong style="color:red">' . $m[2] . '</strong>';
			}

			if (!empty($m[3])) { // most important keywords
				return '<strong style="color:blue">' . $m[3] . '</strong>';
			}

			if (!empty($m[4])) { // other keywords
				return '<strong style="color:green">' . $m[4] . '</strong>';
			}

			return '';
		}, $sql);

		return '<pre class="dump">' . \trim($sql) . "</pre>\n\n";
	}
718502
private function isPoisonedResult($result)
    {
        if ('STATUS:' != substr($result, 0, 7)) {
            return false;
        }

        $parts = explode(':', $result, 3);
        $code  = (int) $parts[1];

        if ($code === 500) {
            return true;
        }

        return false;
    }
1345529
public static function formatResult($result, $decorate = true)
    {
        $name = isset(self::$stateNames[$result]) ? self::$stateNames[$result] : $result;

        return $decorate && $result === Activity::RESULT_FAILURE
            ? '<error>' . $name . '</error>'
            : $name;
    }