Produces a compliant, formatted RFC 2822 'phrase' based on the string given.

@param string $string  as displayed
@param string $charset of the text
@param bool   $shorten the first line to make remove for header name

@return string
549705
protected function createPhrase(Swift_Mime_Header $header, $string, $charset, Swift_Mime_HeaderEncoder $encoder = null, $shorten = false)
    {
        // Treat token as exactly what was given
        $phraseStr = $string;
        // If it's not valid

        if (!preg_match('/^'.self::PHRASE_PATTERN.'$/D', $phraseStr)) {
            // .. but it is just ascii text, try escaping some characters
            // and make it a quoted-string
            if (preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $phraseStr)) {
                $phraseStr = $this->escapeSpecials($phraseStr, ['"']);
                $phraseStr = '"'.$phraseStr.'"';
            } else {
                // ... otherwise it needs encoding
                // Determine space remaining on line if first line
                if ($shorten) {
                    $usedLength = strlen($header->getFieldName().': ');
                } else {
                    $usedLength = 0;
                }
                $phraseStr = $this->encodeWords($header, $string, $usedLength);
            }
        }

        return $phraseStr;
    }
1007626
public static function prepare(string $string, $quotes = '/') : string
    {
        $string = $quotes ? preg_quote($string, $quotes) : $string;

        return str_replace(
            array_keys(self::REGEX_CHARS_REPLACEMENT),
            array_values(self::REGEX_CHARS_REPLACEMENT),
            $string
        );
    }
830400
public static function decodeMimeString($strMime, $charset = null)
    {
        $items = preg_split('/[\r\n]{2,}/si', $strMime);
        $result = '';
        $strArray = [];
        $tmpItems = [];
        foreach ($items as $key => $item) {
            $commaArray = explode('>,', $item);
            if (count($commaArray) > 1) {
                $last = array_pop($commaArray);
                foreach ($commaArray as $value) {
                    $tmpItems[] = $value.'>,';
                }
                $tmpItems[] = $last;
            } else {
                $tmpItems[] = current($commaArray);
            }
        }
        $items = $tmpItems;

        foreach ($items as $key => $item) {
            $data = explode('?', $item);
            $str = '';
            if (!empty($data) && count($data) == 1 && is_null($charset)) {
                $str = $data[0];
            } elseif (!empty($data)) {
                $lastItem = '';
                while (!empty($data)) {
                    $stringPart = self::decodeMimeStringPart($data);
                    if (count($data) == 1) {
                        $lastItem = trim(array_shift($data), ' =');
                    }
                    if (!empty($stringPart)) {
                        $strArray = array_merge_recursive($strArray, $stringPart);
                    }
                }

                if (count($items) === 1 || !empty($lastItem) || (isset($items[$key + 1]) && strpos(trim($items[$key + 1]), '=?') !== 0)) {
                    $str .= self::decodeStrArray($strArray);
                    $strArray = [];
                }

                $str .= $lastItem;
            }
            $result .= $str;
        }
        if (!empty($strArray)) {
            $result .= self::decodeStrArray($strArray);
        }

        if (!empty($charset)) {
            $strMime = mb_convert_encoding($strMime, 'UTF-8', $charset);
        }

        return $result ?: $strMime;
    }
844342
public function normalize(string $string) : string
    {
        if (isset($this->cache[$string])) {
            return $this->cache[$string];
        }

        $result = $this->normalizeChain($string);

        $toCache = array_map(function(RuleInterface $rule) use (&$result) {
            return $result = $rule->apply($result);
        }, $this->rules);

        // Add cache for variants
        array_map(function($index) use ($result) {
            $this->cache[$index] = $result;
        }, $toCache);
        $this->cache[$string] = $result;

        return $result;
    }
1281644
public function escapeAttribute(?string $string, string $charset): string
	{
		if($charset !== 'UTF-8')
		{
			$string = mb_convert_encoding($string, 'UTF-8', $charset);
		}

		$string = preg_replace_callback('/[^a-z0-9,\.\-_]/iSu', [$this, 'attributeEscaper'], $string);

		if($charset !== 'UTF-8')
		{
			$string = mb_convert_encoding($string, $charset, 'UTF-8');
		}

		return $string;
	}
1187330
public function setText($content, $charset = 'utf-8') {
        $this->text = $content;
        $this->textCharset = $charset;
        return $this;
    }
1284891
public function chars($string, $chars = 80, $elide = '...', $splitBy = ' ')
    {
        if (mb_strlen($string) <= $chars) {
            return $string;
        }

        $words = explode($splitBy, $string);
        $newString = '';

        foreach ($words as $word) {
            if (mb_strlen("$newString $word") <= $chars) {
                $newString .= " $word";
            } else {
                break;
            }
        }

        return $newString.$elide;
    }
1225516
public function escapeCSS(?string $string, string $charset): string
	{
		if($string === '' || ctype_digit($string))
		{
			return $string;
		}

		if($charset !== 'UTF-8')
		{
			$string = mb_convert_encoding($string, 'UTF-8', $charset);
		}

		$string = preg_replace_callback('/[^a-z0-9]/iSu', [$this, 'cssEscaper'], $string);

		if($charset !== 'UTF-8')
		{
			$string = mb_convert_encoding($string, $charset, 'UTF-8');
		}

		return $string;
	}
12834
public static function specialtoascii($text, $charset='utf-8') {
        $charset = self::parse_charset($charset);
        $oldlevel = error_reporting(E_PARSE);
        $result = self::typo3()->specCharsToASCII($charset, (string)$text);
        error_reporting($oldlevel);
        return $result;
    }
604949
protected function decode($string)
    {
        $charset = $this->getDataCharset();
        if ($charset !== $this->getConnectionCharset()) {
            $string = iconv($this->getConnectionCharset(), $charset, $string);
        }
        if (get_magic_quotes_gpc()) {
            $string = stripslashes($string);
        }

        return $string;
    }
573899
function strtrunc($charset, $string, $len) {
		if ($len <= 0) {
			return '';
		}

		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') {
			return mb_strcut($string, 0, $len, $charset);
		} elseif ($charset == 'utf-8') {
			return $this->utf8_strtrunc($string, $len);
		} elseif ($this->eucBasedSets[$charset]) {
			return $this->euc_strtrunc($string, $len, $charset);
		} elseif ($this->twoByteSets[$charset]) {
			if ($len % 2) {
				$len--;
			} // don't cut at odd positions
		} elseif ($this->fourByteSets[$charset]) {
			$x = $len % 4;
			$len -= $x; // realign to position dividable by four
		}
			// treat everything else as single-byte encoding
		return substr($string, 0, $len);
	}
735754
function _convertString($string)
    {
        // chop away beggining and ending quotes
        $string = substr($string, 1, strlen($string) - 2);
        if (strlen($string) > 255) {
            return $this->raiseError("String is too long");
        }

        if ($this->_BIFF_version == 0x0500) {
            return pack("CC", $this->ptg['ptgStr'], strlen($string)).$string;
        } elseif ($this->_BIFF_version == 0x0600) {
            $encoding = 0;   // TODO: Unicode support
            return pack("CCC", $this->ptg['ptgStr'], strlen($string), $encoding).$string;
        }
    }
1222934
public static function strtoupper(string $string): string
    {
        return str_replace('ß', 'SS', mb_strtoupper($string, 'UTF-8'));
    }
559835
public function setCharset($charset)
    {
        $prev = $this->charset;

        $charset = strtoupper($charset);
        $charset = null === $charset || 'UTF-8' === $charset || 'UTF8' === $charset ? 'CP1252' : $charset;

        $this->charset = $charset;

        return $prev;
    }
1067812
function parse_charset($charset) {
		$charset = trim(strtolower($charset));
		if (isset($this->synonyms[$charset])) {
			$charset = $this->synonyms[$charset];
		}

		return $charset;
	}
923681
protected function removeChar($string, $charStart = null, $charEnd = null)
    {
        if (!is_null($charStart) && (is_string($charStart) || is_array($charStart))) {
            if (is_string($charStart)) {
                $charStart = [$charStart];
            }

            foreach ($charStart as $char) {
                if (substr($string, 0, 1) === $char) {
                    $string = substr($string, 1);
                }
            }
        }

        if (!is_null($charEnd) && (is_string($charEnd) || is_array($charEnd))) {
            if (is_string($charEnd)) {
                $charEnd = [$charEnd];
            }

            foreach ($charEnd as $char) {
                if (substr($string, -1) === $char) {
                    $string = substr($string, 0, -1);
                }
            }
        }

        return $string;
    }
1169023
public function translate_string($string) {
		if ($this->language->name_short == Config::$base_language) {
			return $string;
		}

		if (!isset($this->strings[$string])) {
			$this->add_to_po($string);
		}

		if ($this->strings[$string] == '') {
			if (Config::$debug) {
				return '[NT]' . $string;
			} else {
				return $string;
			}
		}

		return $this->strings[$string];
	}