Apply all the configured rules to the provided text and return the result
@param $txt string The text to work on
@return string The text with the patterns replaced by their replacements
774306
public function apply($txt)
    {
        if (!is_string($txt))
            throw new \RuntimeException("Argument should be a string");

        foreach ($this->rules as $pattern => $replacement)
        {
            if (is_callable($replacement))
                $txt = preg_replace_callback($pattern, $replacement, $txt);
            else
                $txt = preg_replace($pattern, $replacement, $txt);
        }

        return $txt;
    }
957508
private function _convertTagsToEscapeSequences ( $text ) {
        list($patterns, $replacements) = $this->_getConvertingDictionary();
        $convertedText = preg_replace($patterns, $replacements, $text);
        return $convertedText;
    }
1046790
protected function getEscapedPattern($text)
    {
        $rawPattern = preg_quote($text, '/');

        $escapedPattern = preg_quote(e($text), '/');

        return $rawPattern == $escapedPattern
            ? $rawPattern : "({$rawPattern}|{$escapedPattern})";
    }
741167
private function filter($text)
    {
        $text = preg_replace("/[^&a-z0-9-_\s']/i", '', $text);
        $text = str_replace(' ', $this->separator, $text);
        $text = trim(preg_replace("/{$this->separator}{2,}/", $this->separator, $text), $this->separator);

        return $text;
    }
1099682
public static function translate($text)
    {
        foreach (Config::get('smiley.db_smileys') as $key => $value) {
            $div = "<div class='fst_sml $value'></div>";
            $text = str_replace($key, $div, $text);
        }

        foreach (Config::get('smiley.smileys') as $key => $value) {
            $div = "<div class='fst_sml $value'></div>";
            $text = str_replace($key, $div, $text);
        }
        //
        return $text;
    }
961945
protected static function ucFirst($txt): string
    {
        if (class_exists('\Osf\Stream\Text')) {
            return \Osf\Stream\Text::ucFirst($txt);
        }
        return ucfirst((string) $txt);
    }
1338929
public static function urlize($text)
    {
        $text = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\">\\2</a>", $text);
        $text = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\">\\2</a>", $text);
        $text = preg_replace("/@(\w+)/", "<a href=\"http://twitter.com/\\1\">@\\1</a>", $text);
        $text = preg_replace("/([^&]|^)#(\w+)/", "\\1<a href=\"http://twitter.com/search/\\2\">#\\2</a>", $text);

        return $text;
    }
1177076
public function readWithPattern($text, $pattern) {
		$pieces = explode("\n", $text);
		$result = [];
		foreach ($pieces as $piece) {
			$result[] = sscanf(trim($piece, "\r\n"), $pattern);
		}
		return $result;
	}
925327
public static function makeUrls(string $text) : string
    {
        $urlPattern = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\/\S*)?/";
        preg_match_all($urlPattern, $text, $matches);
        $usedPatterns = array();
        foreach($matches[0] as $pattern){
            if(!array_key_exists($pattern, $usedPatterns)){
                $usedPatterns[$pattern]=true;
                // now try to catch last thing in text
                $text = str_replace($pattern, '<a href="'.$pattern.'" target="_blank">'.$pattern.'</a>', $text);
            }
        }
        return $text;
    }
105078
public function normalizeText( $text )
    {
        if ( $this->searchHandler instanceof LegacyHandler )
        {
            $searchEngine = new eZSearchEngine();
            return $searchEngine->normalizeText( $text );
        }

        return $text;
    }
97168
public static function parseAttributes($text)
    {
        $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
        if (!preg_match_all(self::$attrPattern, $text, $matches, PREG_SET_ORDER)) {
            return array(ltrim($text));
        }
        $attr = array();
        foreach ($matches as $match) {
            if (!empty($match[1])) {
                $attr[strtolower($match[1])] = stripcslashes($match[2]);
            } elseif (!empty($match[3])) {
                $attr[strtolower($match[3])] = stripcslashes($match[4]);
            } elseif (!empty($match[5])) {
                $attr[strtolower($match[5])] = stripcslashes($match[6]);
            } elseif (isset($match[7]) && strlen($match[7])) {
                $attr[] = stripcslashes($match[7]);
            } elseif (isset($match[8])) {
                $attr[] = stripcslashes($match[8]);
            }
        }
        return (array)$attr;
    }
803568
public static function transliterate($txt)
    {
        if ($txt === null) {
            return null;
        }
        return strtolower(\Patchwork\Utf8::toAscii((string) $txt));
    }
601657
public static function replaceStringsAndComments($text)
    {
        if (is_string($text)) {
            // Fast pre-check, to optimize performance
            if (strpos($text, "'") !== false || strpos($text, '"') !== false) {
                // Replace all strings in quotes (also in comments, but that's okay - removed in next step)
                $replaceStringCallback = function ($matches) {
                    return self::addStringReplacement($matches[1] . $matches[2] . $matches[1]);
                };
                $text = preg_replace('/\r/', '', $text);
                $text = preg_replace('/\\\\\n/', '_STRING_CSSLINEBREAK_', $text);
                $text = preg_replace('/\\\\"/', '_STRING_ESCAPEDDOUBLEQUOTE_', $text);
                $text = preg_replace('/\\\\\'/', '_STRING_ESCAPEDSINGLEQUOTE_', $text);
                $text = preg_replace_callback('/("|\')(.*?)\g{1}/', $replaceStringCallback, $text);
            }

            if (strpos($text, "data:") !== false) {
                // Replace all data URIs
                // (that are not in quotes and therefor were not replaced by the previous check)
                $replaceDataUriCallback = function ($matches) {
                    return self::addStringReplacement($matches[1]);
                };
                $text = preg_replace_callback(
                    '/(data:(?:[^;,]+)?(?:;charset=[^;,]+)?' .
                    '(?:;base64,(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?|,[-.a-zA-Z0-9_%]+))/',
                    $replaceDataUriCallback,
                    $text
                );
            }

            // Fast pre-check, to optimize performance
            if (strpos($text, "*") !== false) {
                // Strip multi-line comments (after string replace to keep comments in strings)
                $replaceCommentCallback = function ($matches) {
                    return self::addCommentReplacement($matches[1]);
                };
                $text = preg_replace_callback('/(\/\*.*?\*\/)/', $replaceCommentCallback, $text);
            }

            return $text;
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($text). "' for argument 'text' given."
            );
        }
    }
149283
function leetify( $text )
    {
        $text = preg_replace( "/to/", "2", $text );
        $text = preg_replace( "/for/", "4", $text );
        $text = preg_replace( "/ate/", "8", $text );
        $text = preg_replace( "/you/", "u", $text );
        $text = preg_replace( array( "/l/",
                                     "/e/",
                                     "/o/",
                                     "/a/",
                                     "/t/" ),
                              array( "1",
                                     "3",
                                     "0",
                                     "4",
                                     "7" ), $text );
        return $text;
    }
720083
public function format($text)
    {
        $lines = explode("\n", $text);
        foreach ($lines as &$line) {
            $line = ($this->quote) . str_repeat(' ', $this->indent) . $line;
        }
        return Colour::colour(implode("\n", $lines), $this->foregroundColors, $this->backgroundColors);
    }
730823
protected function replaceTextTokens($text)
    {
        foreach ($this->tokens as $key => $val) {
            $text = str_replace('<' . $key . '>', $val, $text);
        }

        return $text;
    }
75354
public static function format($text) {
		$text = preg_replace_callback('/<b>(.+?)<\/b>/', function($matches) {
			return SS_Cli::text($matches[1], null, null, true);
		}, $text);

		$text = preg_replace_callback('/<success>(.+?)<\/success>/', function($matches) {
			return SS_Cli::text($matches[1], 'green', null, true);
		}, $text);

		$text = preg_replace_callback('/<error>(.+?)<\/error>/', function($matches) {
			return SS_Cli::text($matches[1], 'red', null, true);
		}, $text);

		$text = preg_replace_callback('/<caution>(.+?)<\/caution>/', function($matches) {
			return SS_Cli::text($matches[1], 'yellow', null, true);
		}, $text);

		$text = preg_replace_callback('/<info>(.+?)<\/info>/', function($matches) {
			return SS_Cli::text($matches[1], 'cyan', null, true);
		}, $text);


		return $text;
	}