protected function encodeComponent($str, int $enc_type, string $regexp): ?string
    {
        if (self::NO_ENCODING === $enc_type || null === $str || 1 !== preg_match(self::REGEXP_NO_ENCODING, $str)) {
            return $str;
        }

        return preg_replace_callback($regexp, [$this, 'encodeMatches'], $str) ?? rawurlencode($str);
    }