private function encodeUtf8($string, $options)
    {
        $pattern =
            '/  [\xC2-\xDF][\x80-\xBF]
              |  \xE0[\xA0-\xBF][\x80-\xBF]
              | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}
              |  \xED[\x80-\x9F][\x80-\xBF]
              |  \xF0[\x90-\xBF][\x80-\xBF]{2}
              | [\xF1-\xF3][\x80-\xBF]{3}
              |  \xF4[\x80-\x8F][\x80-\xBF]{2}/x';

        return preg_replace_callback($pattern, function ($match) use ($options) {
            return sprintf($options['hex.capitalize'] ? '\u{%X}' : '\u{%x}', $this->getCodePoint($match[0]));
        }, $string);
    }