Determines the number of char values needed to represent the specified character

@param static|string $char
@return int
@throws InvalidArgumentException
@throws TypeError
493567
public static function charCount($char): int
    {
        self::handleIncomingChar($char);
        $stringChar = (string) $char;

        return mb_ord($stringChar, mb_detect_encoding($stringChar)) > 0xFFFF ? 2 : 1;
    }
1346417
public static int countChar(String string, CharPredicate predicate)
    {
        int count = 0;
        int size = string.length();
        for (int i = 0; i < size; i++)
        {
            if (predicate.accept(string.charAt(i)))
            {
                count++;
            }
        }
        return count;
    }
697481
public static function generate($length = 32, $charset = 'abcdefghijklmnopqrstuvwxyz')
    {
        // Type checks:
        if (!is_numeric($length)) {
            throw new \InvalidArgumentException(
                'random_str - Argument 1 - expected an integer'
            );
        }
        if (!is_string($charset)) {
            throw new \InvalidArgumentException(
                'random_str - Argument 2 - expected a string'
            );
        }

        if ($length < 1) {
            // Just return an empty string. Any value < 1 is meaningless.
            return '';
        }

        // Remove duplicate characters from $charset
        $split = str_split($charset);
        $charset = implode('', array_unique($split));

        // This is the maximum index for all of the characters in the string $charset
        $charset_max = strlen($charset) - 1;
        if ($charset_max < 1) {
            // Avoid letting users do: random_str($int, 'a'); -> 'aaaaa...'
            throw new \LogicException(
                'random_str - Argument 2 - expected a string that contains at least 2 distinct characters'
            );
        }
        // Now that we have good data, this is the meat of our function:
        $random_str = '';
        for ($i = 0; $i < $length; ++$i) {
            $r = random_int(0, $charset_max);
            $random_str .= $charset[$r];
        }

        return $random_str;
    }
845173
public static function CHARACTER($character)
    {
        $character = PHPExcel_Calculation_Functions::flattenSingleValue($character);

        if ((!is_numeric($character)) || ($character < 0)) {
            return PHPExcel_Calculation_Functions::VALUE();
        }

        if (function_exists('mb_convert_encoding')) {
            return mb_convert_encoding('&#'.intval($character).';', 'UTF-8', 'HTML-ENTITIES');
        } else {
            return chr(intval($character));
        }
    }
1003532
protected int charGroup(char c) {
    int         result;

    result = 0;

    if ( (c >= 'a') && (c <= 'z') )
      result = 2;
    else if ( (c >= '0') && (c <= '9') )
      result = 1;

    return result;
  }
774817
private static function handleIncomingChar(...$chars): void
    {
        foreach ($chars as $char) {
            Assert::typeOf(['string', __CLASS__], $char);

            if (mb_strlen((string) $char) !== 1) {
                throw new InvalidArgumentException('Only one character can be represented!');
            }
        }
    }
404384
public function fromRoman($string)
    {
        if (\mb_strlen((string) $string) === 0 || 0 === \preg_match(self::ROMAN_STRING_MATCHER, (string) $string)) {
            throw new \InvalidArgumentException();
        }

        $total = 0;
        $i = \mb_strlen($string);

        while ($i > 0) {
            $digit = $this->map[$string{--$i}];

            if ($i > 0) {
                $previousDigit = $this->map[$string{$i - 1}];

                if ($previousDigit < $digit) {
                    $digit -= $previousDigit;
                    --$i;
                }
            }

            $total += $digit;
        }

        return $total;
    }
855316
protected function value_char()
	{
		$len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
		$this->value .= substr($this->data, $this->position, $len);
		$this->position += $len;
		$this->state = 'value';
	}
1081812
public function charAt($position)
	{
		ArgumentValidator::validateUnsignedInteger($position);
		if ($position >= $this->length()) {
			throw new \InvalidArgumentException('Position invalid');
		}
		return mb_substr($this->string, $position, 1);
	}
1038627
public static function strlen($string, $charset = self::UTF8)
	{
		switch (strtolower($charset))
		{
			case self::GBK:
				$count = self::strlenForGbk($string);
				break;
			case self::UTF8:
				$count = self::strlenForUtf8($string);
				break;
			default:
				$count = strlen($string);
		}
		return $count;
	}
626741
public static function utf8ToCodepoint( $char ) {
		# Find the length
		$z = ord( $char[0] );
		if ( $z & 0x80 ) {
			$length = 0;
			while ( $z & 0x80 ) {
				$length++;
				$z <<= 1;
			}
		} else {
			$length = 1;
		}

		if ( $length != strlen( $char ) ) {
			return false;
		}

		if ( $length == 1 ) {
			return ord( $char );
		}

		# Mask off the length-determining bits and shift back to the original location
		$z &= 0xff;
		$z >>= $length;

		# Add in the free bits from subsequent bytes
		for ( $i = 1; $i < $length; $i++ ) {
			$z <<= 6;
			$z |= ord( $char[$i] ) & 0x3f;
		}

		return $z;
	}
450667
private function getLength(string $string) : ?int
    {
        if (extension_loaded('mbstring') && ! defined('NO_PHP_EXTENSIONS')) { // constant used for tests
            if (! mb_check_encoding($string, 'UTF-8')) {
                return null;
            }

            return mb_strlen($string, 'UTF-8');
        }

        $charLength = 0;

        $length = strlen($string);

        for ($i = 0; $i < $length; $i++) {
            $charLength++;

            $char = ord($string[$i]);

            if ($char < 0x80) { // 0bbbbbbb
                continue;
            }

            if (($char & 0xE0) === 0xC0) { // 110bbbbb
                $n = 1;
            } elseif (($char & 0xF0) === 0xE0) { // 1110bbbb
                $n = 2;
            } elseif (($char & 0xF0) === 0xF0) { // 11110bbb
                $n = 3;
            } else { // invalid char
                return null;
            }

            for ($j = 0; $j < $n; $j++) {
                if (++$i === $length) { // unexpected end of string
                    return null;
                }

                if ((ord($string[$i]) & 0xC0) !== 0x80) { // does not match 10bbbbbb
                    return null;
                }
            }
        }

        return $charLength;
    }
691587
private static function getCodePoint($char)
    {
        if ($char !== htmlspecialchars_decode(htmlspecialchars($char, ENT_COMPAT, 'UTF-8'))) {
            return 0xFFFD;
        }

        $x = ord($char[0]);

        if ($x < 0x80) {
            return $x;
        } elseif ($x < 0xE0) {
            $y = ord($char[1]);

            return (($x & 0x1F) << 6) | ($y & 0x3F);
        } elseif ($x < 0xF0) {
            $y = ord($char[1]);
            $z = ord($char[2]);

            return (($x & 0xF) << 12) | (($y & 0x3F) << 6) | ($z & 0x3F);
        }

        $y = ord($char[1]);
        $z = ord($char[2]);
        $w = ord($char[3]);

        return (($x & 0x7) << 18) | (($y & 0x3F) << 12) | (($z & 0x3F) << 6) | ($w & 0x3F);
    }
1065489
public static function len($string): int
    {
        if (self::isMBString()) {
            return mb_strlen($string, self::$encoding);
        }

        return strlen($string); // @codeCoverageIgnore
    }
883855
private function getCharacterWidth($fontName, $fontSize, $char)
    {
        if (!isset($this->sizes[$fontName][$fontSize][$char])) {
            $this->sizes[$fontName][$fontSize][$char] =
                $this->calculateCharacterWith($fontName, $fontSize, $char);
        }

        return $this->sizes[$fontName][$fontSize][$char];
    }
9846
protected function isLetter($char)
    {
        if ($char === null) {
            return false;
        }

        // Notice: ord(null) will return 0.
        // ord() does not work with utf-8 characters.
        $ascii = ord($char);

        // ASCII codes: 65 = 'A', 90 = 'Z', 97 = 'a', 122 = 'z'
        return (($ascii >= 65 and $ascii <= 90) or ($ascii >= 97 and $ascii <= 122));
    }
177725
public function add($char, $expr)
	{
		$split = $this->input->split($char);
		if (count($split) !== 1)
		{
			throw new InvalidArgumentException('Meta-characters must be represented by exactly one character');
		}
		if (@preg_match('(' . $expr . ')u', '') === false)
		{
			throw new InvalidArgumentException("Invalid expression '" . $expr . "'");
		}

		$inputValue = $split[0];
		$metaValue  = $this->computeValue($expr);

		$this->exprs[$metaValue] = $expr;
		$this->meta[$inputValue] = $metaValue;
	}