Normalizes a tag string by trimming unnecessary whitespace and extracting the tag identifier
from a tag in case it exists.

@param string $tag Tag.
@return array The tag's ID and label.
196739
protected function _normalizeTag($tag) {
		$namespace = null;
		$label = $tag;
		$separator = $this->getConfig('separator');
		if ($separator === null) {
			return [
				null,
				$tag,
			];
		}

		if (strpos($tag, $separator) !== false) {
			list($namespace, $label) = explode($separator, $tag);
		}

		return [
			trim($namespace),
			trim($label)
		];
	}
714651
public function closeTag($tag)
    {
        if (!in_array($tag, $this->voidTags)) {
            return replace_variables($this->closeTagPattern, compact('tag'));
        }

        return '';
    }
701631
static function tagsToString( array $tags ) {

		$tags = wp_list_sort( $tags, 'tag', 'asc' );

		$str = '';
		foreach ( $tags as $tag ) {
			$str .= $tag['tag'] . ', ';
		}

		return rtrim( $str, ', ' );
	}
1137766
private function tag_has_text(string $tag){
    return in_array('text', array_values(
      \is_array($this->tags[$tag]) ?
        $this->tags[$tag] :
        $this->tags[$this->tags[$tag]]
    ));
  }
709305
public function getTags ($tag)
	{
		
		$tags	= array ();
		
		foreach ($this->lines as $line)
		{
			if (strpos ($line, '@' . $tag) === 0)
			{
				$tags[]	= trim (substr ($line, strlen ('@' . $tag)));
			}
		}
		
		return $tags;
		
	}
475303
protected function getFormattedTags(array $tags)
    {
        $add =array();

        foreach ($tags as $key => $value) {
            if (is_bool($value)) {
                $value = $value ? "true" : "false";
            }
            $add[] = "#$key:$value";
        }

        return !empty($add) ? '|'.implode(',', $add) : null;
    }
582747
private function _mangleTags($tags)
    {
        foreach ($tags as $i => $tag) {
            $tags[$i] = $this->_mangleTag($tag);
        }
        return $tags;
    }
54482
public function getTag($tag) {
        if (isset($this->_tags[$tag])) {
            return $this->_tags[$tag];
        }

        throw new MissingFilterException(sprintf('No filter can be found with %s tag', $tag));
    }
1370177
protected function FormatTags($Tags) {
      // Don't bother if there aren't any tags
      if (!$Tags)
         return '';
      
      // Get the array
      $TagsArray = Gdn_Format::Unserialize($Tags);     
      
      // Compensate for deprecated space-separated format 
      if (is_string($TagsArray) && $TagsArray == $Tags)
         $TagsArray = explode(' ', $Tags);
      
      // Safe format
      $TagsArray = Gdn_Format::Text($TagsArray);
      
      // Send back an comma-separated string
      return implode(',', $TagsArray);
   }
1059730
public static function serializeTags(array $tags)
    {
        if (empty($tags))
            return '';

        self::validateTags($tags);
        $tagstrs = array();
        foreach ($tags as $tag)
            $tagstrs[] = $tag->toString(true);

        return implode(';', $tagstrs);
    }
811034
public function untag($tags = null)
    {
        if (empty($tags)) {
            return $this->_updateTags([], 'replace');
        }

        $table = TableRegistry::getTableLocator()->get($this->source());
        $behavior = $table->behaviors()->Tag;
        $assoc = $table->getAssociation($behavior->getConfig('tagsAlias'));
        $property = $assoc->getProperty();
        $id = $this->get($table->getPrimaryKey());
        $untags = $behavior->normalizeTags($tags);

        $tags = $this->get($property);
        if (!$tags) {
            $contain = [$behavior->getConfig('tagsAlias')];
            $tags = $table->get($id, compact('contain'))->get($property);
        }

        $tagsTable = $table->{$behavior->getConfig('tagsAlias')};
        $pk = $tagsTable->getPrimaryKey();
        $df = $tagsTable->getDisplayField();

        foreach ($tags as $k => $tag) {
            $tags[$k] = [
                $pk => $tag->{$pk},
                $df => $tag->{$df},
            ];
        }

        foreach ($untags as $untag) {
            foreach ($tags as $k => $tag) {
                if ((empty($untag[$pk]) || $tag[$pk] === $untag[$pk]) &&
                    (empty($untag[$df]) || $tag[$df] === $untag[$df])
                ) {
                    unset($tags[$k]);
                }
            }
        }

        return $this->_updateTags(
            array_map(
                function ($i) {
                    return implode(':', $i);
                },
                $tags
            ),
            'replace'
        );
    }
471946
public function normalizeTags($tags) {
		if (is_string($tags)) {
			$tags = explode($this->getConfig('delimiter'), $tags);
		}

		$result = [];

		$modelAlias = $this->getConfig('fkModelAlias') ?: $this->_table->getAlias();

		$common = ['_joinData' => [$this->getConfig('fkModelField') => $modelAlias]];
		$namespace = $this->getConfig('namespace');
		if ($namespace) {
			$common += compact('namespace');
		}

		$tagsTable = $this->_table->{$this->getConfig('tagsAlias')};
		$primaryKey = $tagsTable->getPrimaryKey();
		$displayField = $tagsTable->getDisplayField();

		foreach ($tags as $tag) {
			$tag = trim($tag);
			if (empty($tag)) {
				continue;
			}
			$tagKey = $this->_getTagKey($tag);
			$existingTag = $this->_tagExists($tagKey);
			if (!empty($existingTag)) {
				$result[] = $common + ['id' => $existingTag];
				continue;
			}
			list($id, $label) = $this->_normalizeTag($tag);
			$result[] = $common + compact(empty($id) ? $displayField : $primaryKey) + [
				'slug' => $tagKey,
			];
		}

		return $result;
	}
1233444
private function getTagIdByName( $tag )
    {
        $tagSql = $this->sql( $this->getTableInSchema( static::$tagTableName ) );

        $select = $tagSql->select()
                         ->columns( array( 'id' ) )
                         ->where( array(
                             new TypedParameters(
                                 'LOWER(?) = ?',
                                 array(
                                     'name',
                                     mb_strtolower( $tag, 'UTF-8' ),
                                 ),
                                 array(
                                     TypedParameters::TYPE_IDENTIFIER,
                                     TypedParameters::TYPE_VALUE,
                                 )
                             ),
                         ) );

        $result = $tagSql->prepareStatementForSqlObject( $select )
                         ->execute();

        foreach ( $result as $row )
        {
           return $row['id'];
        }

        return null;
    }
161999
private function parseTag($tag, $context)
    {
        // ensure tag is an object
        $this->instantiatTag($tag);
        // extract context
        $value = isset($context['value']) ? $context['value'] : false;
        $sub = isset($context['sub']) ? $context['sub'] : false;
        // the sub value can contain escaped values, those values must be parsed back into the original state.
        if ($sub) {
            $sub = str_replace(['\)', '\('], [')', '('], $sub);
        }
        // run parse method inside the tag object.
        return $this->tags[$tag]->parse($value, $sub);
    }
720330
protected function _nextTaggedLine(&$tag)
    {
        $line = $this->_nextLine();

        // seperate tag from line
        list($tag, $line) = explode(' ', $line, 2);

        return $line;
    }
821799
public static function tagIncrementVer($tag)
        {
            if (!$tag) {
                return false;
            }

            $time = microtime(true) * 10000;

            if (is_array($tag)) {
                foreach ($tag as $tagName) {
                    self::GetInstance()->set("\$vxnTag:{$tagName}", $time, null, self::$ttlTags);
                    if (self::$useTagsBuffer) {
                        self::$tagsBuffer[$tagName] = $time;
                    }
                }

                return true;
            }
            else if (is_string($tag) || is_numeric($tag)) {
                self::GetInstance()->set("\$vxnTag:{$tag}", $time, null, self::$ttlTags);
                if (self::$useTagsBuffer) {
                    self::$tagsBuffer[$tag] = $time;
                }

                return $time;
            }

            throw new \TypeError("'\$tag' expected to be an array, string or numeric, got " . gettype($tag));
        }
307746
public function findIdentifiersByTag(string $tag): array
    {
        if (isset($this->tagsAndEntries[$tag])) {
            return array_keys($this->tagsAndEntries[$tag]);
        }
        return [];
    }