@param array $matches

@return string
@see attributeValue()
183416
private static function numericEntitiesSingleByte($matches)
    {
        $buffer = str_split($matches[0]);
        foreach ($buffer as &$char) {
            $char = sprintf('&#%d;', ord($char));
        }

        return implode('', $buffer);
    }
836984
protected function parseDocReturn( $matches )
	{
		$return	= new ADT_PHP_Return( trim( $matches[1] ) );
		if( isset( $matches[2] ) )
			$return->setDescription( trim( $matches[2] ) );
		return $return;
	}
963685
protected function camelcaseReplace($matches): string
    {
        if (function_exists('mb_convert_case')) {
            return mb_convert_case($matches[0], MB_CASE_TITLE, "UTF-8");
        }
        
        return ucfirst(strtolower($matches[0]));
    }
480711
private static function htmlEncodingCallback($matches)
    {
        $characterIndex = 1;
        $entities = '';

        $codes = unpack('C*', htmlentities($matches[0], ENT_COMPAT, 'UTF-8'));

        while (isset($codes[$characterIndex])) {
            if (0x80 > $codes[$characterIndex]) {
                $entities .= chr($codes[$characterIndex++]);

                continue;
            }

            if (0xF0 <= $codes[$characterIndex]) {
                $code = (($codes[$characterIndex++] - 0xF0) << 18) + (($codes[$characterIndex++] - 0x80) << 12) + (($codes[$characterIndex++] - 0x80) << 6) + $codes[$characterIndex++] - 0x80;
            } elseif (0xE0 <= $codes[$characterIndex]) {
                $code = (($codes[$characterIndex++] - 0xE0) << 12) + (($codes[$characterIndex++] - 0x80) << 6) + $codes[$characterIndex++] - 0x80;
            } else {
                $code = (($codes[$characterIndex++] - 0xC0) << 6) + $codes[$characterIndex++] - 0x80;
            }

            $entities .= '&#' . $code . ';';
        }

        return $entities;
    }
499907
private function castToEntity($matches)
    {
        $entities = $this->entityRegistry->getEntityBuilder()->castToEntity($matches, $this->entityClass);

        return $entities;
    }
1182698
private function normalize(array $matches) : array
    {
        $keys = $matches[1];
        $values = $matches[2];

        $return = [];

        foreach ($keys as $i => $key) {
            $key = strtolower(trim($key));

            if ($key == 'mode') {
                $value = strtolower($values[$i]);
            } else {
                $value = array_map(
                    function ($el) {
                        return trim($el, ', ');
                    },
                    explode(',', $values[$i])
                );
            }
            $return[$key] = $value;
        }

        return $return;
    }
552139
protected static function __match(array $patterns)
    {
        return function (...$args) use ($patterns) {
            $parameterTypes = array_map(self::getType(), $args);

            try {
                $keysToValues = Arrays::zip(array_keys($patterns), array_values($patterns));

                list($key, $matchingPattern) = Arrays::first(
                    Pattern::patternApplies($parameterTypes, $args),
                    $keysToValues
                );
            } catch (ElementNotFoundException $e) {
                throw new IncompletePatternMatchException(
                    'Incomplete pattern match expression. (missing ' . implode(', ', $parameterTypes) . ')'
                );
            }


            /**
             * Upcoming Feature, Array DSL for matching via `x::xs` etc.
             */
//            // if key is a string, manually match
//            if (is_string($key)) {
//
//                throw new \Exception('Array DSL not available.');
//            }

            list($hasExtractable, $unwrappedArgs) = self::unwrapArgs($args);

            $value = $matchingPattern(...$args);
            $isCallable = is_callable($value);

            if ($hasExtractable && ! $isCallable) {
                throw new InvalidPatternMatchException(
                    'Invalid pattern match expression. (one of ' . implode(', ', $parameterTypes)
                    . ' requires a callback to unwrap)'
                );
            }

            /**
             * Extractable requires a callback to feed args into.
             */
            if ($hasExtractable && $isCallable) {
                return $matchingPattern(...$args)(...$unwrappedArgs);
            }

            /**
             * No extractable so we can just return the value directly.
             */
            return $value;
        };
    }
127337
private function generateAttributes(array $matches): Generator
    {
        foreach ($matches as $match) {
            $m = array_filter($match);
            $key = $m[1] ?? $m[3] ?? $m[5] ?? $m[7] ?? $m[8] ?? $m[9];
            $stringMatch = $m[2] ?? $m[4] ?? $m[6] ?? false;
            $value = $stringMatch ? stripcslashes($stringMatch) : true;
            yield strtolower($key) => $value;
        }
    }
967006
protected function getVariableValue(array $matches)
    {
        $res = $matches[0];
        $variable = substr($matches[0], 1, -1);

        if (isset($this->frontmatter[$variable])) {
            $res = $this->frontmatter[$variable];
        }

        return $res;
    }
1250679
public function _parseParams(array $matches)
    {
        $params = array();
        foreach ($matches as $k => $v) {
            if (is_numeric($k)) {
                if ($k === 0) {
                    continue;
                }
                $params[] = $v;
            } else {
                $params[$k] = $v;
            }
        }
        return new Set($params);
    }
132751
protected function parseDocParameter( $matches )
	{
		$parameter	= new ADT_PHP_Parameter( $matches[4], $matches[2] );
		if( isset( $matches[5] ) )
			$parameter->setDescription( $matches[5] );
		return $parameter;
	}
1155871
protected function _encodeCallback(array $matches) {
        $cacheSize = count($this->_cache);
        $this->_cache[$cacheSize] = $matches[2];

        return '[code' . $matches[1] . ']$$CODE' . $cacheSize . '$$[/code]';
    }
172445
private function parse_callback($matches)
    {
    	$method = $matches[1];
    	//$params = str_replace(array('"', '\''), '', $matches[2]);
    	$params = $this->addquote($matches[2]);
    	switch ($method) {
    	    case 'template':
    		case 'include':
    			$content = '<?php include $this->template(' . $params . '); ?>';
    			break;
    		case 'layout':
    		    $content = '<!-- php__layout(' . $params . ') -->';
    		    break;
    	}
    	
    	return isset($content) ? '' . $this->addquote($content) : '';
    }
386246
private function _filter(array $matches)
    {
        $filters = explode('|', $matches[0]);
        $var = $filters[0];
        unset($filters[0]);
        foreach ($filters as $filter) {
            $params = explode(':', $filter);
            $filterName = $params[0];
            unset($params[0]);
            $array = 'array(';
            foreach ($params as $param) {
                $array .= $param . ',';
            }
            $array = trim($array, ',') . ')';
            $var = 'getFilter(\'' . $filterName . '\')->setOptions(' . $array . ')->filter(' . $var . ')';
        }
        return $var;
    }
221620
protected function attributes(array $attributes): string
	{
		$attr = '';

		foreach($attributes as $attribute => $value)
		{
			if(is_int($attribute))
			{
				$attribute = $value;
			}

			$attr .= ' ' . $attribute . '="' . $value . '"';
		}

		return $attr;
	}
212486
protected function linkifyCb($matches)
    {
        $uri = (isset($matches[1]) && strlen(trim($matches[1]))) ? $matches[0] : "http://" . $matches[0];

        // we dont want to link if it would cause malformed HTML
        $openTags = array();
        $closeTags = array();
        preg_match_all("/<(?!\/)([^\s>]*).*?>/", $matches[0], $openTags, PREG_SET_ORDER);
        preg_match_all("/<\/([^\s>]*).*?>/", $matches[0], $closeTags, PREG_SET_ORDER);

        if (count($openTags) != count($closeTags)) {
            return $matches[0];
        }
        if (isset($openTags[0]) && trim($openTags[0][1]) !== trim($closeTags[0][1])) {
            return $matches[0];
        }

        $uri = strip_tags($uri);

        $target = ($this->strictStandards) ? '' : ' target="_blank"';
        return "<a href='{$uri}' class='link'{$target}>{$matches[0]}</a>";
    }
1027052
private function findString($i, array $matches)
    {
        $string = isset($matches[0][$i]) ? $matches[0][$i] : '';


        return substr($string, 1, -1);
    }