Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Iconv.php

function Iconv::mapFromUtf8

1 call to Iconv::mapFromUtf8()
Iconv::iconv in vendor/symfony/polyfill-iconv/Iconv.php

File

vendor/symfony/polyfill-iconv/Iconv.php, line 658

Class

Iconv
iconv implementation in pure PHP, UTF-8 centric.

Namespace

Symfony\Polyfill\Iconv

Code

private static function mapFromUtf8(&$result, array $map, $str, $ignore, $translit) {
    $ulenMask = self::$ulenMask;
    $valid = self::$isValidUtf8;
    if ($translit && !self::$translitMap) {
        self::$translitMap = self::getData('translit');
    }
    $i = 0;
    $len = \strlen($str);
    while ($i < $len) {
        if ($str[$i] < "\x80") {
            $uchr = $str[$i++];
        }
        else {
            $ulen = $str[$i] & "\xf0";
            $ulen = $ulenMask[$ulen] ?? 1;
            $uchr = substr($str, $i, $ulen);
            if ($ignore && (1 === $ulen || !($valid || preg_match('/^.$/us', $uchr)))) {
                ++$i;
                continue;
            }
            $i += $ulen;
        }
        if (isset($map[$uchr])) {
            $result .= $map[$uchr];
        }
        elseif ($translit) {
            if (isset(self::$translitMap[$uchr])) {
                $uchr = self::$translitMap[$uchr];
            }
            elseif ($uchr >= "À") {
                $uchr = \Normalizer::normalize($uchr, \Normalizer::NFD);
                if ($uchr[0] < "\x80") {
                    $uchr = $uchr[0];
                }
                elseif ($ignore) {
                    continue;
                }
                else {
                    return false;
                }
            }
            elseif ($ignore) {
                continue;
            }
            else {
                return false;
            }
            $str = $uchr . substr($str, $i);
            $len = \strlen($str);
            $i = 0;
        }
        elseif (!$ignore) {
            return false;
        }
    }
    return true;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal