Looks up the passed charset in self::$iconvAliases, returning the mapped
charset if applicable.  Otherwise returns charset.

@param string $cs
@return string the mapped charset (if mapped) or $cs otherwise
353222
private function getIconvAlias($cs)
    {
        $normalized = $this->getNormalizedCharset($cs);
        if (array_key_exists($normalized, self::$iconvAliases)) {
            return static::$iconvAliases[$normalized];
        }
        return $cs;
    }
974292
def get_charset(message, default="utf-8"):
    """"""
    if message.get_content_charset():
        return message.get_content_charset()
    if message.get_charset():
        return message.get_charset()
    return default
404716
protected function fetchCssPseudoContainsSelector($string, $caseSensitive = false)
    {
        if ($caseSensitive) {
            return sprintf('text() = "%s"', $string);
        }

        if (function_exists('mb_strtolower')) {
            return sprintf(
                'php:functionString("mb_strtolower", .) = php:functionString("mb_strtolower", "%s")',
                $string
            );
        } else {
            return sprintf('php:functionString("strtolower", .) = php:functionString("strtolower", "%s")', $string);
        }
    }
707059
public function ere2pcre(string $s, bool $ignorecase): string
    {
        static $cache = [], $icache = [];
        if ($ignorecase) {
            if (isset($icache[$s])) {
                return $icache[$s];
            }
        } else {
            if (isset($cache[$s])) {
                return $cache[$s];
            }
        }
        [$r, $i] = $this->_ere2pcre($s, 0);
        if ($i !== strlen($s)) {
            throw new InvalidEregException('unescaped metacharacter ")"');
        }

        if ($ignorecase) {
            return $icache[$s] = '#' . $r . '#mi';
        }

        return $cache[$s] = '#' . $r . '#m';
    }
529711
public static function GetMimeTypeCharsetByCharset ($charset) {
		$charset_map = static::GetCharsetMapForMimeType();
		return isset($charset_map[$charset]) ? $charset_map[$charset] : null;
	}
1037452
private static function unicodeChar($dec)
    {
        if ($dec < 0x80) {
            return chr($dec);
        }

        if ($dec < 0x0800) {
            return chr(0xC0 + ($dec >> 6))
                .chr(0x80 + ($dec & 0x3f));
        }

        if ($dec < 0x010000) {
            return chr(0xE0 + ($dec >> 12))
                    .chr(0x80 + (($dec >> 6) & 0x3f))
                    .chr(0x80 + ($dec & 0x3f));
        }

        if ($dec < 0x200000) {
            return chr(0xF0 + ($dec >> 18))
                    .chr(0x80 + (($dec >> 12) & 0x3f))
                    .chr(0x80 + (($dec >> 6) & 0x3f))
                    .chr(0x80 + ($dec & 0x3f));
        }
    }
537963
protected function parseListOfIcons()
    {
        $cache = $this->cacheManager->getCache('Default');
        $cacheId = 'FontIconDataSource_parseListOfIcons';

        if (!($icons = $cache->get($cacheId))) {
            $icons = [];
            foreach (file(self::$iconsListFilePath) as $content) {
                if (preg_match('#fa-var-([-_a-z0-9]+):#i', $content, $match)) {
                    $icons[] = $match[1];
                }
            }

            $cache->set($cacheId, $icons, [], 0);
        }

        return $icons;
    }
1006210
private static function supportsCsvEscapeChar()
    {
        if (self::$csvEscapeChar === null) {
            self::$csvEscapeChar = version_compare(PHP_VERSION, '5.5.4') >= 0;
        }

        return self::$csvEscapeChar;
    }
105162
public static function cssStringToArray($css)
    {
        $statements = explode(';', preg_replace('/\s+/s', ' ', $css));
        $styles = array();
        foreach ($statements as $statement) {
            $statement = trim($statement);
            if ('' === $statement) {
                continue;
            }
            $p = strpos($statement, ':');
            if ($p <= 0) {
                continue;
            } // invalid statement, just ignore it
            $key = trim(substr($statement, 0, $p));
            $value = trim(substr($statement, $p + 1));
            $styles[$key] = $value;
        }
        return $styles;
    }
909193
public static function to_unicode($s)
	{
		if (! ReflectionTypeHint::isValid()) return false;
		if (is_null($s)) return $s;

		$s2 = null;
		#since PHP-5.3.x iconv() little faster then mb_convert_encoding()
		if (function_exists('iconv')) $s2 = @iconv('UTF-8', 'UCS-4BE', $s);
		elseif (function_exists('mb_convert_encoding')) $s2 = @mb_convert_encoding($s, 'UCS-4BE', 'UTF-8');
		if (is_string($s2)) return array_values(unpack('N*', $s2));
		if ($s2 !== null) return false;

		$a = self::str_split($s);
		if ($a === false) return false;
		return array_map(array(__CLASS__, 'ord'), $a);
	}
312743
public function translateChar($dec)
    {
        if (isset($this->mapping[$dec])) {
            $dec = $this->mapping[$dec];
        }

        return $dec;
    }
1017678
protected function convertCharset($string, $charsets)
    {
        if (function_exists('iconv')
            && !empty($charsets)
        ) {
            $charset = $charsets[0];
            if (count($charsets) > 1
                && function_exists('mb_detect_encoding')
            ) {
                $charset = mb_detect_encoding($string, $charsets);
                if ($charset === false) {
                    $charset = $charsets[0];
                }
            }

            $newKey = @iconv($charset, 'UTF-8//IGNORE', $string);
            if (!empty($newKey)) {
                $string = $newKey;
            }
        }

        return $string;
    }
608227
public function getAsString(): string
    {
        $text = iconv(
            $this->source->getEncoding(),
            $this->getEncoding(),
            $this->source->getAsString()
        );
        if (false === $text) {
            throw new SourceException('iconv failed to convert source text');
        }

        return $text;
    }
784182
public function toASCII($source)
    {
        if (function_exists('iconv') && $this->config()->use_iconv) {
            return $this->useIconv($source);
        } else {
            return $this->useStrTr($source);
        }
    }
135722
protected function codePointToChar($code)
    {
        if ($code <= 0x7F) {
            return chr($code);
        } elseif ($code <= 0x7FF) {
            return chr(($code >> 6) + 192) . chr(($code & 63) + 128);
        } elseif ($code <= 0xFFFF) {
            return chr(($code >> 12) + 224) . chr((($code >> 6) & 63) + 128) . chr(($code & 63) + 128);
        } else {
            return chr(($code >> 18) + 240) . chr((($code >> 12) & 63) + 128) . chr((($code >> 6) & 63) + 128) . chr(($code & 63) + 128);
        }
    }
468565
public static function parse_charset($charset) {
        $charset = strtolower($charset);

        // shortcuts so that we do not have to load typo3 on every page

        if ($charset === 'utf8' or $charset === 'utf-8') {
            return 'utf-8';
        }

        if (preg_match('/^(cp|win|windows)-?(12[0-9]{2})$/', $charset, $matches)) {
            return 'windows-'.$matches[2];
        }

        if (preg_match('/^iso-8859-[0-9]+$/', $charset, $matches)) {
            return $charset;
        }

        if ($charset === 'euc-jp') {
            return 'euc-jp';
        }
        if ($charset === 'iso-2022-jp') {
            return 'iso-2022-jp';
        }
        if ($charset === 'shift-jis' or $charset === 'shift_jis') {
            return 'shift_jis';
        }
        if ($charset === 'gb2312') {
            return 'gb2312';
        }
        if ($charset === 'gb18030') {
            return 'gb18030';
        }

        // fallback to typo3
        return self::typo3()->parse_charset($charset);
    }
91466
function specCharsToASCII($charset, $string) {
		if ($charset == 'utf-8') {
			$string = $this->utf8_char_mapping($string, 'ascii');
		} elseif (isset($this->eucBasedSets[$charset])) {
			$string = $this->euc_char_mapping($string, $charset, 'ascii');
		} else {
				// treat everything else as single-byte encoding
			$string = $this->sb_char_mapping($string, $charset, 'ascii');
		}

		return $string;
	}