function CharacterStream::getUtf8CharPositions
1 call to CharacterStream::getUtf8CharPositions()
- CharacterStream::write in vendor/
symfony/ mime/ CharacterStream.php
File
-
vendor/
symfony/ mime/ CharacterStream.php, line 167
Class
- CharacterStream
- @author Fabien Potencier <fabien@symfony.com> @author Xavier De Cock <xdecock@gmail.com>
Namespace
Symfony\Component\MimeCode
private function getUtf8CharPositions(string $string, int $startOffset, string &$ignoredChars) : int {
$strlen = \strlen($string);
$charPos = \count($this->map['p']);
$foundChars = 0;
$invalid = false;
for ($i = 0; $i < $strlen; ++$i) {
$char = $string[$i];
$size = self::UTF8_LENGTH_MAP[$char];
if (0 == $size) {
/* char is invalid, we must wait for a resync */
$invalid = true;
continue;
}
if ($invalid) {
/* We mark the chars as invalid and start a new char */
$this->map['p'][$charPos + $foundChars] = $startOffset + $i;
$this->map['i'][$charPos + $foundChars] = true;
++$foundChars;
$invalid = false;
}
if ($i + $size > $strlen) {
$ignoredChars = substr($string, $i);
break;
}
for ($j = 1; $j < $size; ++$j) {
$char = $string[$i + $j];
if ($char > "" && $char < "\xc0") {
// Valid - continue parsing
}
else {
/* char is invalid, we must wait for a resync */
$invalid = true;
continue 2;
}
}
/* Ok we got a complete char here */
$this->map['p'][$charPos + $foundChars] = $startOffset + $i + $size;
$i += $j - 1;
++$foundChars;
}
return $foundChars;
}