Switch the Encoding mode

@return AlphanumericMode | EightBitMode | NumericMode
178597
private function switchMode()
    {
        switch ( $this->getModeName() )
        {
            case self::NUMERIC_MODE:
                return new NumericMode;

            case self::ALPHA_NUMERIC_MODE:
                return new AlphanumericMode;

            case self::EIGHT_BITS_MODE:
            default:
                return new EightBitMode;
        }
    }
1074019
public function editionMode() {
		if (isset($_SESSION["FINE_MESSAGE_EDITION_MODE"])) {
			$this->isMessageEditionMode = true;
		}
		$this->content->addFile('../utils.i18n.fine/src/views/enableDisableEdition.php', $this);
		$this->template->toHtml();
	}
682301
public static function getIsMbstringEnabled()
	{
		if (isset(self::$_isMbstringEnabled)) {
			return self::$_isMbstringEnabled;
		}

		self::$_isMbstringEnabled = function_exists('mb_convert_encoding') ?
			true : false;

		return self::$_isMbstringEnabled;
	}
1227751
protected function getEncodedEOLDelimiter()
    {
        if (!isset($this->encodedEOLDelimiter)) {
            $this->encodedEOLDelimiter = $this->encodingHelper->attemptConversionFromUTF8($this->inputEOLDelimiter, $this->encoding);
        }

        return $this->encodedEOLDelimiter;
    }
991346
public function getBinary()
    {
        $data = '';

        $guid = str_replace('-', '', $this->value);

        foreach ($this->octetSections as $section) {
            $data .= $this->parseSection($guid, $section, true);
        }

        return hex2bin($data);
    }
1284903
public static function getIsMbstringEnabled()
    {
        if (isset(self::$isMbstringEnabled)) {
            return self::$isMbstringEnabled;
        }

        self::$isMbstringEnabled = function_exists('mb_convert_encoding') ?
            true : false;

        return self::$isMbstringEnabled;
    }
39166
public function swapCase()
    {
        return $this->newSelf(preg_replace_callback
        (
            '/[\S]/u',
            function ($match)
            {
                $marchToUpper = UTF8::strtoupper($match[0], $this->encoding);

                if ($match[0] == $marchToUpper)
                {
                    return UTF8::strtolower($match[0], $this->encoding);
                }
                else
                {
                    return $marchToUpper;
                }
            },
            $this->scalarString
        ));
    }
1184040
public function toUInt8()
    {
        $binary = $this->getBinary();
        $split = str_split($binary, 1);

        // argument *by-reference*
        array_walk($split, function(&$item, $ix) {
            $buf = new Buffer($item, 1);
            $item = (int) $buf->getInt();
        });

        return $split;
    }
65409
public function encoding() {
		$db = $this->_getConnection();
		$config = $db->config();
		$database = $config['database'];
		$prefix = ''; //$config['prefix'];
		$encoding = 'utf8mb4';
		$collate = 'utf8mb4_unicode_ci';

		try {
			$script = "ALTER DATABASE $database CHARACTER SET $encoding COLLATE $collate;";
			if (!$this->params['dry-run']) {
				$db->query($script);
			} else {
				$this->out($script);
			}
		} catch (Exception $e) {
			$this->err('Could not alter database: ' . $e->getMessage() . ' - Skipping.');
		}

		$script = <<<SQL
SELECT  CONCAT('ALTER TABLE `', table_name, '` CONVERT TO CHARACTER SET $encoding COLLATE $collate;') AS statement
FROM    information_schema.tables AS tb
WHERE   table_schema = '$database'
AND     table_name LIKE '$prefix%'
AND     `TABLE_TYPE` = 'BASE TABLE';
SQL;
		/** @var \Cake\Database\Statement\StatementDecorator $res */
		$res = $db->query($script);
		if (!$res) {
			$this->abort('Nothing to do...');
		}

		$script = [];
		foreach ($res as $r) {
			$script[] = $r['statement'];
		}

		if (!$this->param('dry-run')) {
			$continue = $this->in(count($res) . ' tables will be altered.', ['Y', 'N'], 'N');
			if (strtoupper($continue) !== 'Y') {
				$this->abort('Aborted!');
			}
		}

		foreach ($script as $row) {
			preg_match('/`(.+)`/', $row, $matches);
			$table = $matches[1];
			$sql = "ALTER TABLE `$table` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;";

			if ($this->params['interactive']) {
				$in = $this->in('Fix table ' . $table . '?', ['y', 'n'], 'y');
				if ($in !== 'y') {
					$this->out(' - skipping ' . $table);
					continue;
				}
			}

			if (!$this->params['dry-run']) {
				$this->out(' - fixing table ' . $table, 1, Shell::VERBOSE);
				$db->query($row);
				$db->query($sql);
			} else {
				$this->out($row);
				$this->out($sql);
			}
		}
		$this->out('Done :)');
	}
968663
public function getFormat()
    {
        switch (true) {
            case ($this->encoder instanceof Base32Encoder):
                $format = self::FORMAT_BASE32;
                break;
            case ($this->encoder instanceof HexEncoder):
                $format = self::FORMAT_HEX;
                break;
            case ($this->encoder instanceof RawEncoder):
            default:
                $format = self::FORMAT_RAW;
        }

        return $format;
    }
149650
@CheckReturnValue
  @Override
  public EncodingOptions buildOptions() {
    // TODO When/if modelmapper supports @ConstructorProperties, we map this
    // object, instead of doing new XXX(...)
    // https://github.com/jhalterman/modelmapper/issues/44
    return new EncodingOptions(
        new MainEncodingOptions(format, startOffset, duration),
        new AudioEncodingOptions(
            audio_enabled,
            audio_codec,
            audio_channels,
            audio_sample_rate,
            audio_sample_format,
            audio_bit_rate,
            audio_quality),
        new VideoEncodingOptions(
            video_enabled,
            video_codec,
            video_frame_rate,
            video_width,
            video_height,
            video_bit_rate,
            video_frames,
            video_filter,
            video_preset));
  }
1068992
public static function encodeUtf8($strValue = '', $strEncoding = 'iso-8859-1', $booSafemode = false)
    {
        return encode_utf8($strValue = '', $strEncoding = 'iso-8859-1', $booSafemode = false);
    }
835505
public byte[] encode() {
        byte[] bytes;
        switch (sizeOf(value)) {
            case 1:
                return new byte[]{(byte) value};
            case 3:
                bytes = new byte[3];
                bytes[0] = (byte) 253;
                Utils.uint16ToByteArrayLE((int) value, bytes, 1);
                return bytes;
            case 5:
                bytes = new byte[5];
                bytes[0] = (byte) 254;
                Utils.uint32ToByteArrayLE(value, bytes, 1);
                return bytes;
            default:
                bytes = new byte[9];
                bytes[0] = (byte) 255;
                Utils.int64ToByteArrayLE(value, bytes, 1);
                return bytes;
        }
    }
14471
public function asUTF8String(): Primitive\UTF8String
    {
        if (!$this->_element instanceof Primitive\UTF8String) {
            throw new \UnexpectedValueException(
                $this->_generateExceptionMessage(Element::TYPE_UTF8_STRING));
        }
        return $this->_element;
    }
1126872
protected function encode()
    {
        if ($this->useIconv) {
            $this->fileContent = iconv($this->encoding, 'UTF-8', $this->fileContent);
        } else {
            $this->fileContent = mb_convert_encoding($this->fileContent, 'UTF-8', $this->encoding);
        }
    }
315259
public function setOptions($options)
    {
        if ($this->step !== null) {
            throw new \RuntimeException('Cannot change encoding options during encoding');
        }

        $this->options = (int) $options;
        return $this;
    }
868248
protected function getFormatOptionsFromPost()
    {
        $presetMode = post('format_preset');

        $options = [
            'delimiter' => null,
            'enclosure' => null,
            'escape' => null,
            'encoding' => null
        ];

        if ($presetMode == 'custom') {
            $options['delimiter'] = post('format_delimiter');
            $options['enclosure'] = post('format_enclosure');
            $options['escape'] = post('format_escape');
            $options['encoding'] = post('format_encoding');
        }

        return $options;
    }