Converts the string to a new encoding
@link https://php.net/manual/en/mbstring.supported-encodings.php
@param string $newEncoding
@return \static
169328
public function convertEncoding($newEncoding){

		if(!\is_string($newEncoding)){
			throw new \InvalidArgumentException('$newEncoding must be a string');
		}
		
		$newEncoding = \strtoupper($newEncoding);
		
		return new static(\mb_convert_encoding($this->_Value, $newEncoding, $this->_Encoding),
				$newEncoding);
		
	}
286555
public function encodeString($str, $encoding = 'base64')
    {
        $encoded = '';
        switch (strtolower($encoding)) {
            case 'base64':
                $encoded = chunk_split(
                    base64_encode($str),
                    static::STD_LINE_LENGTH - strlen(static::$LE),
                    static::$LE
                );
                break;
            case '7bit':
            case '8bit':
                $encoded = static::normalizeBreaks($str);
                // Make sure it ends with a line break
                if (substr($encoded, -(strlen(static::$LE))) != static::$LE) {
                    $encoded .= static::$LE;
                }
                break;
            case 'binary':
                $encoded = $str;
                break;
            case 'quoted-printable':
                $encoded = $this->encodeQP($str);
                break;
            default:
                $this->setError($this->lang('encoding') . $encoding);
                break;
        }

        return $encoded;
    }
574178
public function convert(string $string): string
    {
        if ($this->encoding === null) {
            $this->encoding = $this->getEncoding($string);
        }

        if ($this->encoding === self::UTF16BE) {
            $string = mb_convert_encoding($string, "UTF-8", "UTF-16BE");
        }

        if ($this->encoding === self::UTF16LE) {
            $string = mb_convert_encoding($string, "UTF-8", "UTF-16LE");
        }

        return $string;
    }
1144794
protected static function convertBodyEncoding($body, $charset = '', $encoding = -1)
    {
        if ('' === $charset) {
            $charset = static::$charset;
        }

        if (!mb_check_encoding($body, $charset)) {
            $charset = mb_detect_encoding($body);
        }

        if ($charset === static::$charset) {
            return $body;
        }

        if (!in_array($charset, mb_list_encodings())) {
            $charset = $encoding === ENC7BIT ? 'US-ASCII' : static::$charset;
        }

        return mb_convert_encoding($body, static::$charset, $charset);
    }
1020248
public EncodingWriter create(String javaEncoding)
  {
    try {
      return new OutputStreamEncodingWriter(javaEncoding);
    } catch (UnsupportedEncodingException e) {
      log.log(Level.WARNING, e.toString(), e);
      
      return null;
    }
  }
7049
protected static function clientEncoding()
	{
		if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']))
		{
			return false;
		}

		$encoding = false;

		if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
		{
			$encoding = 'gzip';
		}

		if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip'))
		{
			$encoding = 'x-gzip';
		}

		return $encoding;
	}
1526
public static function setDefaultEncoding($encoding=null)
    {
        if(!is_null($encoding) && is_string($encoding) && !empty($encoding))
        {
            self::$defaultencoding = $encoding;
        }
        else
        {
            self::$defaultencoding = null;
        }
    }
639551
public static function convertEncoding($string, $to, $from)
    {
        if (!function_exists('mb_convert_encoding'))
        {
            throw new \RuntimeException(
                'StringEscaper requires mbstring extension to be installed when escaping for non UTF-8 strings.'
            );
        }

        //Convert character encoding
        $result = mb_convert_encoding($string, $to, $from);

        // Return non-fatal blank string on encoding errors from users
        $result = $result !== false ? $result : '';

        return $result;
    }
1110529
public static function to($encodingLabel, $text)
    {
        $encodingLabel = static::normalizeEncoding($encodingLabel);

        if ($encodingLabel == 'ISO-8859-1') {
            return static::toLatin1($text);
        }

        return static::toUTF8($text);
    }
1144315
public static function newFromString(string $content): self
    {
        $document = Xml::newDocumentContent($content);
        // populate source since it is already available
        // in this way we avoid the conversion from document to string
        $cfdi = new self($document);
        $cfdi->source = $content;
        return $cfdi;
    }
1048624
public function setHeaderEncoding($encoding)
    {
        $allowed = array(
            Zend_Mime::ENCODING_BASE64,
            Zend_Mime::ENCODING_QUOTEDPRINTABLE
        );
        if (!in_array($encoding, $allowed)) {
            /**
             * @see Zend_Mail_Exception
             */
            // require_once 'Zend/Mail/Exception.php';
            throw new Zend_Mail_Exception('Invalid encoding "' . $encoding . '"');
        }
        $this->_headerEncoding = $encoding;

        return $this;
    }
67749
public static function conv_from($str, $fsencoding) {
        if ($fsencoding != '' && $fsencoding != self::$encoding) {
            $str = iconv($fsencoding, self::$encoding, $str);
        }
        return $str;
    }
51684
public static function encode($input, $encoding)
    {
        switch (strtolower($encoding)) {
            case 'utf-8':
                $output = $input;
                break;
            
            case 'x-user-defined':
                $output = preg_replace_callback('/[^\\x00-\\x7F]/u', function ($matches) {
                    $codePoint = self::getCodePoint($matches[0]);
                    return $codePoint <= 0xF7FF ? chr($codePoint - 0xF780 + 0x80) : '&#' . $codePoint . ';';
                }, $input);
                break;
            
            default:
                $output = self::convertEncoding($input, $encoding);
        }
        
        return $output;
    }
1295471
public static function convertEncodingRecursive( $var, $to_encoding = NULL, $from_encoding = NULL )
    {
        $type = gettype($var);
        switch( $type ){
        case 'string':
            {
                return mb_convert_encoding($var,$to_encoding, $from_encoding);
            }
            break;
        case 'integer':
        case 'double':
        case 'boolean':
        case 'NULL':
        case 'unknown type':
            break;
        case 'array':
            {
                $newArray = array();
                foreach( $var as $key => $value ){
                    $value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
                    $newArray[ $key ] = $value;
                }
                return $newArray;
            }
            break;
        case 'object':
            {
                $newObject = clone $var;
                if ( $var instanceof \Traversable ){
                    foreach( $var as $key => $value ){
                        $value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
                        $newObject->$key = $value;
                    }
                    return $newObject;
                }
                else{
                    $obj_vars = get_object_vars( $var );
                    foreach( $obj_vars as $key => $value ){
                        $value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
                        $newObject->$key = $value;
                    }
                    return $newObject;
                }
            }
            break;
        }

        return $var;
    }
380974
public static function setEncoding($encoding) {

		if(false === is_string($encoding) || 0 === strlen($encoding)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($encoding)), E_USER_ERROR);
		}

		$encoding = strtolower($encoding);

		if(false === in_array($encoding, static :: $encodings)) {
			return trigger_error(sprintf('Argument 1 passed to %s() is not a supported encoding. Provide an encoding supported by htmlspecialchars()', __METHOD__), E_USER_ERROR);
		}

		static :: $encoding = $encoding;
	}
542120
public function replace($old, $new): self
    {
        Assert::typeOf(['string', __CLASS__], $old, $new);

        return new static(str_replace((string) $old, (string) $new, $this->data), $this->encoding);
    }
512362
protected static function filterEncoding(string $encoding): string
    {
        static $encoding_list;
        if (null === $encoding_list) {
            $list = mb_list_encodings();
            $encoding_list = array_combine(array_map('strtolower', $list), $list);
        }

        $key = strtolower($encoding);
        if (isset($encoding_list[$key])) {
            return $encoding_list[$key];
        }

        throw new OutOfRangeException(sprintf('The submitted charset %s is not supported by the mbstring extension', $encoding));
    }