UNB line analysis

@param string|string[] $encoding UNB definition line (without UNB tag). Example UNOA:2

@return void
493684
public function analyseUNB($encoding)
    {
        if (\is_array($encoding)) {
            $encoding = $encoding[0];
        }

        $this->encoding = $encoding;

        // If there's a regex defined for this character set, use it.
        /** @noinspection OffsetOperationsInspection */
        if (isset(self::$encodingToStripChars[$encoding])) {
            /** @noinspection OffsetOperationsInspection */
            $this->setStripRegex(self::$encodingToStripChars[$encoding]);
        }

        $this->unbChecked = true;
    }
655217
public static function get($encoding) {
        if (isset(self::$aliases[strtolower($encoding)])) {
            return self::$aliases[strtolower($encoding)];
        } else {
            return $encoding;
        }
    }
1330971
public static function decode(array $encoded)
    {
        $encoded = static::reverseIfLittleEndian($encoded);

        $doubles = unpack(PackFormat::FLOAT_32, static::convertToString($encoded));
        return array_shift($doubles);
    }
272535
protected static function decode($body, $encoding)
    {
        if (ENCQUOTEDPRINTABLE === $encoding) {
            return quoted_printable_decode($body);
        }

        if (ENCBASE64 === $encoding) {
            return base64_decode($body);
        }

        return $body;
    }
763325
private function encodeChar(&$data, $encoding, $seq, $text, &$i, &$counter, &$indcheck) {
        if (isset($seq[$i + 1]) && $seq[$i + 1] === 'F') {
            // We have a flag !!
            if ($text[$counter + 1] === 'F') {
                $number = $text[$counter + 2];
                $fnc = $this->fnc[$encoding][$number - 1];
                $indcheck[] = $fnc;
                $data[] = $this->code[$fnc];

                // Skip F + number
                $counter += 2;
            } else {
                // Not supposed
            }

            $i++;
        } else {
            if ($encoding === 2) {
                // We take 2 numbers in the same time
                $code = (int)substr($text, $counter, 2);
                $indcheck[] = $code;
                $data[] = $this->code[$code];
                $counter++;
                $i++;
            } else {
                $keys = ($encoding === 0) ? $this->keysA : $this->keysB;
                $pos = strpos($keys, $text[$counter]);
                $indcheck[] = $pos;
                $data[] = $this->code[$pos];
            }
        }

        $counter++;
    }
1236168
public void setEncoding(String encoding)
    throws UnsupportedEncodingException
  {
    if (encoding != null) {
      _readEncoding = Encoding.getReadEncoding(this, encoding);
      _readEncodingName = Encoding.getMimeName(encoding);
    }
    else {
      _readEncoding = null;
      _readEncodingName = null;
    }
  }
108053
public static function encode($str, $encoding, $EOL = self::LINEEND)
    {
        switch ($encoding) {
            case self::ENCODING_BASE64:
                return self::encodeBase64($str, self::LINELENGTH, $EOL);

            case self::ENCODING_QUOTEDPRINTABLE:
                return self::encodeQuotedPrintable($str, self::LINELENGTH, $EOL);

            default:
                /**
                 * @todo 7Bit and 8Bit is currently handled the same way.
                 */
                return $str;
        }
    }
148929
private static function unescapeRef($encoded)
    {
        $decoded = '';
        $length = strlen($encoded);
        for ($i = 0; $i < $length; $i++) {
            $char = $encoded[$i];
            if ($char === '~' && $i !== $length - 1) {
                $next = $encoded[$i + 1];
                if ($next === '0') { // escaped `~`
                    $decoded .= '~';
                    $i++;
                } elseif ($next === '1') { // escaped `/`
                    $decoded .= '/';
                    $i++;
                } else {
                    // this ~ had special meaning :-(
                    $decoded .= $char;
                }
            } else {
                $decoded .= $char;
            }
        }
        return $decoded;
    }
876582
public function setEncoding($direction, $encoding)
    {
        if (!isset($this->encoding[$direction])) {
            throw new Exception("Encoding direction invalid");
        }

        if (!$encoding) {
            throw new Exception("Encoding value invalid");
        } elseif (preg_match('/utf.?8/ui', $encoding)) {
            $encoding = 'UTF-8';
        } else {
            $encoding = mb_strtoupper($encoding);
        }

        $this->encoding[$direction] = $encoding;

        return $this;
    }
203060
public function checkCollation ($encoding = 'utf8', $exception = true)
		{
			$variables = [
				'character_set_client',
				'character_set_connection',
				'character_set_database',
				'character_set_results',
				'character_set_server',
				'character_set_system',
				'collation_connection',
				'collation_database',
				'collation_server'
			];
			foreach ($variables as $variable)
			{
				$sql = "show variables like '" . $variable . "'";
				$value = $this->db->createCommand($sql)->queryOne();
				$pos = StringHelper::pos($value[ 'Value' ], $encoding);
				if ($pos !== 0)
				{
					if (!$exception)
						return false;
					else
						throw new InvalidConfigException ("Parameter $variable does not match $encoding.");
				}
			}

			return true;
		}
1164953
public static function unserial($code)
    {
        $codeArr = array();

        $codeLines = explode("\n", gzuncompress($code));
        foreach ($codeLines as $line)
            $codeArr[] = str_split($line);

        return $codeArr;
    }
1159505
private static function decode_value($value, $encoding)
    {
        switch (strtolower($encoding)) {
        case 'quoted-printable':
            self::$values_decoded = true;
            return quoted_printable_decode($value);

        case 'base64':
        case 'b':
            self::$values_decoded = true;
            return base64_decode($value);

        default:
            return $value;
        }
    }
1229882
public function upper($str, $encoding = null)
	{
		$encoding or $encoding = $this->encoding;

		return function_exists('mb_strtoupper')
			? mb_strtoupper($str, $encoding)
			: strtoupper($str);
	}
93919
private function encoding( $array, $to_encoding = 'UTF-8', $from_encoding = 'GBK' ) : array
	{
		$encoded = [];
		foreach( $array as $key => $value ){
			if( is_array( $value ) ){
				$encoded[$key] = $this->encoding( $value, $to_encoding, $from_encoding );
			} elseif( is_bool( $value ) ){
				$encoded[$key] = $value;
			} elseif( is_string( $value ) && mb_detect_encoding( $value, 'UTF-8', true ) ){
				$encoded[$key] = $value;
			} else{
				$encoded[$key] = mb_convert_encoding( $value, $to_encoding, $from_encoding );
			}
		}
		return $encoded;
	}
349576
public function upper($encoding = null)
    {
        if (!$this->hasMbstring()) {
            return $this->transform('\strtoupper');
        }

        $encoding = $this->encoding($encoding);

        return $this->transform('\mb_convert_case', MB_CASE_UPPER, $encoding);
    }
1284029
public function isCharset($string, $encoding)
    {
        return strtoupper($this->detect($string, [], true)) == strtoupper($encoding);
    }
299293
public function setEncoding($encoding)
    {
        if (empty($encoding))
            throw new \InvalidArgumentException('The encoding may not be empty or NULL.');
        if (!is_string($encoding))
            throw new \InvalidArgumentException('The encoding must be a string.');

        $this->encoding = $encoding;

        return $this;
    }