Maps an internal charset to one understood by MySQL.
If the charset is unknown, it will be returned as is.

@param string $charset Charset to map.

@return string The converted charset.

@since 4.4
346919
public static function mapTo( $charset )
    {
        $lowerCharset = strtolower( $charset );
        return isset( self::$mapping[$lowerCharset] ) ? self::$mapping[$lowerCharset] : $charset;
    }
713290
public function setCharset($charset, $method = null)
    {
        if ($method === null) {
            $method = $this->getConfig('method');
        }

        $this->query($method . ' ' . $charset);

        return $this->getConnect()->set_charset($charset);
    }
794730
private function _source_result_charset()
     {
        if( preg_match("/^utf/", $this->targetCharSet) ) {
           $rs = 1;
        }
        else if( preg_match("/^gb/", $this->targetCharSet) ) {
           $rs = 2;
        }
        else if( preg_match("/^big/", $this->targetCharSet) ) {
           $rs = 3;
        }
        else {
            $rs = 4;
        }
        return $rs;
     }
567757
public function set_charset($charset)
	{
		// Make sure the database is connected
		$this->_connection or $this->connect();

		// Set Charset for SQL Server connection
		if (strtolower($this->driver_name()) == 'sqlsrv')
		{
			$this->_connection->setAttribute(\PDO::SQLSRV_ATTR_ENCODING, \PDO::SQLSRV_ENCODING_SYSTEM);
		}
		// Set Charset for SQLite connection
		elseif (strtolower($this->driver_name()) == 'sqlite')
		{
			// Execute a raw PRAGMA encoding query
			$this->_connection->exec('PRAGMA encoding = ' . $this->quote($charset));
		}
		// Set Charset for any connection except ODBC, as it throws exception
		elseif (strtolower($this->driver_name()) != 'odbc')
		{
			// Execute a raw SET NAMES query
			$this->_connection->exec('SET NAMES '.$this->quote($charset));
		}
	}
273596
public Charset setCharset(Charset charset) {
        Charset prev = this.charset.get();
        this.charset.set(charset);
        return prev;
    }
1097657
public function setCharset($charset)
    {
        if (GenericValidator::validateCharset($charset)) {
            $this->charset = $charset;
            return true;
        }
        return false;
    }
425246
public function str($len, $_charset = null) {
    if($_charset == null) {
      $_charset = $this->_charset;
    }

    $str = '';
    for ($i = 0; $i < $len; $i++) {
      $pos = $this->int(0,strlen($_charset)-1);
      $str .= $_charset[$pos];
    }
    return $str;
  }
1253552
public function charset($charset = null)
    {
        deprecationWarning('Email::charset() is deprecated. Use Email::setCharset() or Email::getCharset() instead.');

        if ($charset === null) {
            return $this->getCharset();
        }
        $this->setCharset($charset);

        return $this->charset;
    }
22181
public function setCharset( string $charset = 'UTF8' ) : MySQL
   {

      if ( ! $this->_supportedAttributes->get( 'charset' )->validateValue( $charset ) )
      {
         throw new ArgumentException( 'charset', $charset, 'Invalid charset!' );
      }

      $this->_attributes[ 'charset' ] = $charset;

      return $this;

   }
472919
public function charset($charset = null)
    {
        if (!func_num_args()) {
            return $this->_stream->charset();
        }
        $this->_stream->charset($charset);
        return $this;
    }
825810
public function setCharset($charset)
    {
        parent::setCharset($charset);
        if (isset($this->paramEncoder)) {
            $this->paramEncoder->charsetChanged($charset);
        }
    }
854026
public function charset($charset = null)
    {
        if (!func_num_args()) {
            list($mime, $charset) = $this->_inspectContentType();
            return $this->_charset = $charset;
        }
        $this->_charset = $charset ? strtoupper($charset) : null;
        $this->_updateContentType();
        return $this;
    }
1176648
public function setCharset($charset)
    {
        $this->clearCachedValueIf($charset != $this->charset);
        $this->charset = $charset;
        if (isset($this->encoder)) {
            $this->encoder->charsetChanged($charset);
        }
    }
1038627
public static function strlen($string, $charset = self::UTF8)
	{
		switch (strtolower($charset))
		{
			case self::GBK:
				$count = self::strlenForGbk($string);
				break;
			case self::UTF8:
				$count = self::strlenForUtf8($string);
				break;
			default:
				$count = strlen($string);
		}
		return $count;
	}
1208889
public static function convert_from($data, $charset = 'cp1251')
	{
		if (! ReflectionTypeHint::isValid()) return false;
		return self::_convert($data, $charset, 'UTF-8');
	}
1144947
function generateCharsetMappingTable( $unicodeTable, $charset )
    {
        $codec = eZTextCodec::instance( 'unicode', $charset );
        if ( !$codec )
        {
            eZDebug::writeError( "Failed to create textcodec for charset '$charset'" );
            return false;
        }

        $charsetTable = array();
        foreach ( $unicodeTable as $match => $replacement )
        {
            $matchLocal = $codec->convertString( array( $match ) );
            if ( is_array( $replacement ) )
            {
                $replacementLocal = $codec->convertString( $replacement );
            }
            else
            {
                $replacementLocal = $codec->convertString( array( $replacement ) );
            }
            $charsetTable[$matchLocal] = $replacementLocal;
        }

        // Make sure longer string entries are placed before the shorter ones
        // This is very important when working with utf8 which have
        // variable length for characters
        krsort( $charsetTable );
        return $charsetTable;
    }
761653
public static function length($string, $charset = 'UTF-8')
    {
        $charset = self::lower($charset);

        if ($charset == 'utf-8' || $charset == 'utf8') {
            return strlen(utf8_decode($string));
        }

        if (Horde_Util::extensionExists('mbstring')) {
            $ret = @mb_strlen($string, self::_mbstringCharset($charset));
            if (!empty($ret)) {
                return $ret;
            }
        }
        if (Horde_Util::extensionExists('intl')) {
            return grapheme_strlen(
                self::convertCharset($string, $charset, 'UTF-8')
            );
        }

        return strlen($string);
    }