private function resolveInputEncoding($string)
    {
        $encoding = null;

        if ($this->detect) {
            $encoding = mb_detect_encoding($string, null, true);
        }

        // Fall back to the internal encoding
        if (false === $encoding || null === $encoding) {
            $encoding = mb_internal_encoding();
        }

        if (false === $encoding || null === $encoding) {
            throw EncodingDetectionException::forString($string);
        }

        return $encoding;
    }