Used to normalize string before passing
it to detectors

@param string $text

@return string
960710
protected function prepare($text)
    {
        if ($this->getConfig('asciiConversion', true)) {
            setlocale(LC_ALL, 'en_us.UTF8');

            $text = iconv('UTF-8', 'ASCII//TRANSLIT', $text);
        }

        $text = trim(strtolower($text));
        $text = str_replace(["\t", "\r\n", "\r", "\n"], "", $text);

        // Convert some characters that 'MAY' be used as alias
        $text = str_replace(["@", "$", "[dot]", "(dot)"], ["at", "s", ".", "."], $text);

        // Strip multiple dots (.) to one. eg site......com to site.com
        $text = preg_replace("/\.{2,}/", ".", $text);

        // Remove special characters
        return preg_replace("/[^a-zA-Z0-9-\.\s]/", "", $text);
    }
677481
public static String normalize(final String text, final Configuration config){
        if(text != null && config.isNormalizeLabelText()){
            return text.trim().replaceAll("[\n\r]", "").replaceAll("[\t 　]+", " ");
        }
        return text;
    }
604619
protected function parseAttr($text)
    {
        $atts = [];

        $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';

        $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);

        if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) )
        {
            foreach ($match as $m)
            {
                if (!empty($m[1]))
                    $atts[strtolower($m[1])] = stripcslashes($m[2]);
                elseif (!empty($m[3]))
                    $atts[strtolower($m[3])] = stripcslashes($m[4]);
                elseif (!empty($m[5]))
                    $atts[strtolower($m[5])] = stripcslashes($m[6]);
                elseif (isset($m[7]) and strlen($m[7]))
                    $atts[] = stripcslashes($m[7]);
                elseif (isset($m[8]))
                    $atts[] = stripcslashes($m[8]);
            }
        }
        else
        {
            $atts = ltrim($text);
        }

        return $atts;
    }
923609
public function parse($text)
    {
        if (empty($text)) {
            return '';
        }

        return $this->driver->text(
            static::removeLeadingWhitespace($this->escape($text))
        );
    }
1192532
protected function doHardBreaks($text) {
		if ($this->hard_wrap) {
			return preg_replace_callback('/ *\n/', 
				array($this, '_doHardBreaks_callback'), $text);
		} else {
			return preg_replace_callback('/ {2,}\n/', 
				array($this, '_doHardBreaks_callback'), $text);
		}
	}
930783
protected static function removeTrailingNewline($text)
    {
        return substr($text, - 1) === "\n" ? substr($text, - 2, 1) === "\r" ? substr($text, 0, - 2) : substr($text, 0, - 1) : $text;
    }
1179186
static function CorrectSpaces($text)
    {
        $chars = '!,;.?:';
        $charArray = str_split($chars);
        foreach ($charArray as $char)
        {
            $text = Str::Replace($char, $char . ' ', $text);
        }
        return  self::RemoveMultipleSpaces($text);
    }
689199
public function convertToUrl($text)
    {
        $text =$this->convertToCode($text);
        $text = str_replace("_", "-", $text);
        return $text;
    }
1176987
public static function removeAccents($text){
    static $diac;
    return strtr(
      utf8_decode($text),
      $diac ? $diac : $diac = utf8_decode('àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'),
      'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
  }
866405
static function strtolower( $text )
    {
        //We need to detect our internal charset
        if ( self::$charset === null )
        {
            self::$charset = eZTextCodec::internalCharset();
        }

        //First try to use mbstring
        if ( extension_loaded( 'mbstring' ) )
        {
            return mb_strtolower( $text, self::$charset );
        }
        else
        {
            // Fall back if mbstring is not available
            $char = eZCharTransform::instance();
            return $char->transformByGroup( $text, 'lowercase' );
        }
    }
519294
public static function ampReplace($text)
    {
        $text = str_replace([
            '&&',
            '&#',
            '&#',
            '&amp;',
            '*-*',
            '*--*',
        ], [
            '*--*',
            '*-*',
            '*-*',
            '&',
            '&#',
            '&&',
        ], $text);

        $text = (string)preg_replace('/|&(?![\w]+;)|/', '&amp;', $text);

        return $text;
    }
999493
protected static String preNormalize(String text) {
    String normalizedText = text.toLowerCase();
    normalizedText = Chronic.numericizeNumbers(normalizedText);
    normalizedText = normalizedText.replaceAll("['\"\\.]", "");
    normalizedText = normalizedText.replaceAll("([/\\-,@])", " $1 ");
    normalizedText = normalizedText.replaceAll("\\btoday\\b", "this day");
    normalizedText = normalizedText.replaceAll("\\btomm?orr?ow\\b", "next day");
    normalizedText = normalizedText.replaceAll("\\byesterday\\b", "last day");
    normalizedText = normalizedText.replaceAll("\\bnoon\\b", "12:00");
    normalizedText = normalizedText.replaceAll("\\bmidnight\\b", "24:00");
    normalizedText = normalizedText.replaceAll("\\bbefore now\\b", "past");
    normalizedText = normalizedText.replaceAll("\\bnow\\b", "this second");
    normalizedText = normalizedText.replaceAll("\\b(ago|before)\\b", "past");
    normalizedText = normalizedText.replaceAll("\\bthis past\\b", "last");
    normalizedText = normalizedText.replaceAll("\\bthis last\\b", "last");
    normalizedText = normalizedText.replaceAll("\\b(?:in|during) the (morning)\\b", "$1");
    normalizedText = normalizedText.replaceAll("\\b(?:in the|during the|at) (afternoon|evening|night)\\b", "$1");
    normalizedText = normalizedText.replaceAll("\\btonight\\b", "this night");
    normalizedText = normalizedText.replaceAll("(?=\\w)([ap]m|oclock)\\b", " $1");
    normalizedText = normalizedText.replaceAll("\\b(hence|after|from)\\b", "future");
    normalizedText = Chronic.numericizeOrdinals(normalizedText);
    return normalizedText;
  }
638715
public function noSpec($text = "")
    {
        $text = preg_replace("#[" . preg_quote("'`\\|>!`~^<%)(&") . "]#", "", $text);
        $text = str_replace('"', '\"', $text);

        return $text;
    }
600766
protected function normalizeChain(string $string): string
    {
        if (null === $this->chain) {
            return $string;
        }

        return $this->chain
                ->normalize($string);
    }
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;
	}
957508
private function _convertTagsToEscapeSequences ( $text ) {
        list($patterns, $replacements) = $this->_getConvertingDictionary();
        $convertedText = preg_replace($patterns, $replacements, $text);
        return $convertedText;
    }
625535
protected static function checkColons($text)
    {
        if (strpos($text, ':') !== false
        || strpos($text, '[') !== false
        || strpos($text, '{') !== false
        || strpos($text, '-') !== false
        || strpos($text, '<') !== false
        || strpos($text, '&') !== false
        ) {
            return '"'.str_replace('"', '\"', $text).'"';
        }

        return $text;
    }