Normalize the name of a BBCode

Follows the same rules as tag names with one exception: "*" is kept for compatibility with
other BBCode engines

@param  string $bbcodeName Original name
@return string             Normalized name
165724
public static function normalizeName($bbcodeName)
	{
		if ($bbcodeName === '*')
		{
			return '*';
		}

		if (!TagName::isValid($bbcodeName))
		{
			throw new InvalidArgumentException("Invalid BBCode name '" . $bbcodeName . "'");
		}

		return TagName::normalize($bbcodeName);
	}
325029
protected function _normalizeName($name)
    {
        if (!is_string($name) || $name === '' )
            throw new \Exception(sprintf(
                'Name must be a none empty string, you injected (%s).'
                , \Poirot\Std\flatten($name)
            ));

        if (isset($this->_c_normalizedNames[$name]))
            return $this->_c_normalizedNames[$name];

        $canonicalName = strtolower(
            // TODO better normalize function replace none digit and words with '' except \\ as separator
            strtr($name, array('-'=>'', '.'=>'', '=>', '\\'=>self::SEPARATOR))
        );

        if (strstr($name, self::SEPARATOR) !== false)
            throw new \Exception(sprintf(
                'Service Or Alias Name Cant Contains Separation String (%s).'
                , self::SEPARATOR
            ));

        return $this->_c_normalizedNames[$name] = $canonicalName;
    }
1179094
public static function PrefixFromQName( $qname )
	{
		if ( $qname instanceof Undefined )
		{
			return $qname;
		}

		if ( ! $qname instanceof QNameValue )
		{
			throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::XPTY0004,
				array(
					SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $qname ), XmlTypeCardinality::One ),
					"QName"
				)
			);
		}

		/**
		 * @var QNameValue $qnameValue
		 */
		$qnameValue = $qname;

		return $qnameValue->Prefix == ""
			? Undefined::getValue()
			: $qnameValue->Prefix;
	}
488676
public function baseName($baseName = null)
    {
        if ($baseName !== null) {
            $this->baseName = rtrim($baseName, '/') . '/';
        }

        return $this->baseName;
    }
990688
public static function normalizeName($name)
    {
        if (false !== ($pos = strrpos($name, '.'))) {
            $name = substr($name, $pos + 1);
        }

        return $name;
    }
957881
public static function normalizeSvgAttribute($name) {
        $name = strtolower($name);
        if (isset(static::$svgCaseSensitiveAttributeMap[$name])) {
            $name = static::$svgCaseSensitiveAttributeMap[$name];
        }

        return $name;
    }
1358196
public function normalizeLink($url)
    {
        if( property_exists($this,'normalizeLink') && is_callable($this->normalizeLink)){
            $fn = $this->normalizeLink;
            return $fn($url);
        }
        $parsed = $this->mdurl->parse($url, true);

        if ($parsed->hostname) {
            // Encode hostnames in urls like:
            // `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
            //
            // We don't encode unknown schemas, because it's likely that we encode
            // something we shouldn't (e.g. `skype:name` treated as `skype:host`)
            //
            $is = false;
            foreach (self::RECODE_HOSTNAME_FOR as &$v) {
                if( ($is = $v === $parsed->protocol) ) break;
            }
            if (empty($parsed->protocol) || $is) {
                try {
                    $parsed->hostname = $this->punycode->toASCII($parsed->hostname);
                } catch (\Exception $e) { /**/ }
            }
        }

        return $this->mdurl->encode($this->mdurl->format($parsed));
    }
151737
public static function normalize($name)
	{
		if (!static::isValid($name))
		{
			throw new InvalidArgumentException("Invalid tag name '" . $name . "'");
		}

		// Non-namespaced tags are uppercased
		if (strpos($name, ':') === false)
		{
			$name = strtoupper($name);
		}

		return $name;
	}
752182
private function normalizeHeaderName($header)
    {
        if (strpos($header, 'HTTP_') === 0) {
            $header = str_replace('_', '-', substr($header, 5));
        }
        return strtolower($header);
    }
731205
protected function parseBBCode($bbcode):string{
		static $callback_count = 0;

		$callback = false;

		if(is_array($bbcode) && count($bbcode) === 4){
			[$match, $tag, $attributes, $content] = $bbcode;

			$tag        = strtolower($tag);
			$attributes = $this->parseAttributes($attributes);
			$callback   = true;

			$callback_count++;
		}
		else if(is_string($bbcode) && !empty($bbcode)){
			$match      = null;
			$tag        = null;
			$attributes = [];
			$content    = $bbcode;
		}
		else{
			return '';
		}

		if($callback_count < $this->limit && !in_array($tag, $this->noparse , true)){
			$content = preg_replace_callback('#\[(\w+)((?:\s|=)[^]]*)?]((?:[^[]|\[(?!/?\1((?:\s|=)[^]]*)?])|(?R))*)\[/\1]#', __METHOD__, $content);
			$e = preg_last_error();

			/**
			 * 1 - PREG_INTERNAL_ERROR
			 * 2 - PREG_BACKTRACK_LIMIT_ERROR
			 * 3 - PREG_RECURSION_LIMIT_ERROR
			 * 4 - PREG_BAD_UTF8_ERROR
			 * 5 - PREG_BAD_UTF8_OFFSET_ERROR
			 * 6 - PREG_JIT_STACKLIMIT_ERROR
			 */
			if($e !== PREG_NO_ERROR){
				$this->logger->debug('preg_error', ['errno' => $e, '$content' => $content]);

				$content = $match ?? '';//$content ?? $bbcode ??
			}
		}

		if($callback === true && in_array($tag, $this->allowed, true)){
			$content = $this->outputInterface->transform($tag, $attributes, $content, $match, $callback_count);
			$callback_count = 0;
		}

		return $content;
	}
123030
function normalizeImageName( $imageName )
    {
        // Initialize transformation system
        $trans = eZCharTransform::instance();

        $imageName = eZURLAliasML::convertToAlias( $imageName );
        return $imageName;
    }
1321455
public static function coerceName( $name ) {
		$coercedName =
			mb_encode_numericentity( mb_substr( $name, 0, 1, 'UTF-8' ),
				HTMLData::$nameStartCharConvTable, 'UTF-8', true ) .
			mb_encode_numericentity( mb_substr( $name, 1, null, 'UTF-8' ),
				HTMLData::$nameCharConvTable, 'UTF-8', true );
		$coercedName = preg_replace_callback( '/&#x([0-9A-F]*);/',
			function ( $m ) {
				return 'U' . str_pad( $m[1], 6, '0', STR_PAD_LEFT );
			},
			$coercedName );
		return $coercedName;
	}
1187626
protected function normalizeName($name)
    {
        if ($this->hasSuffix($name)) {
            $lenSuffix = strlen($this->suffix);
            $name = substr($name, 0, -$lenSuffix);
        }

        return $name;
    }
443399
public function asConfig()
	{
		$bbcodes = parent::asConfig();
		foreach ($bbcodes as $bbcodeName => &$bbcode)
		{
			// Remove the tag name if it's the same name as the BBCode
			if (isset($bbcode['tagName'])
			 && TagName::isValid($bbcodeName)
			 && TagName::normalize($bbcodeName) === $bbcode['tagName'])
			{
				unset($bbcode['tagName']);
			}

			// Remove the defaultAttribute name if it's the same name as the BBCode
			if (isset($bbcode['defaultAttribute'])
			 && AttributeName::isValid($bbcodeName)
			 && AttributeName::normalize($bbcodeName) === $bbcode['defaultAttribute'])
			{
				unset($bbcode['defaultAttribute']);
			}
		}
		unset($bbcode);

		return new Dictionary($bbcodes);
	}
1210891
public static function renderValidNodeName($name)
    {
        // Check if name already match name pattern to prevent unnecessary transliteration
        if (preg_match(NodeInterface::MATCH_PATTERN_NAME, $name) === 1) {
            return $name;
        }

        $originalName = $name;

        // Transliterate (transform 北京 to 'Bei Jing')
        $name = Transliterator::transliterate($name);

        // Urlization (replace spaces with dash, special special characters)
        $name = Transliterator::urlize($name);

        // Ensure only allowed characters are left
        $name = preg_replace('/[^a-z0-9\-]/', '', $name);

        // Make sure we don't have an empty string left.
        if ($name === '') {
            $name = 'node-' . strtolower(md5($originalName));
        }

        return $name;
    }
1216394
protected function normalizeName($name)
    {
        if ($this->files->extension($name) === $this->extension) {
            $name = substr($name, 0, - (strlen($this->extension) + 1));
        }

        return $name;
    }
1126091
public function getNormalizeModuleNameByClassName($className)
    {
        if (!array_key_exists($className, $this->normalizeModuleNameByClassName)) {
            $moduleName = $this->getModuleNameByClassName($className);
            $this->normalizeModuleNameByClassName[$className] = rtrim($moduleName, '\\');
        }

        return $this->normalizeModuleNameByClassName[$className];
    }