@param string $directiveString

@return bool
977446
public static function isDirectiveStringValid($directiveString)
    {
        $directiveString = trim($directiveString);

        if ($directiveString === '') {
            return false;
        }

        if (!self::doesDirectiveStringContainFieldValueSeparator($directiveString)) {
            return false;
        }

        if (!self::doesDirectiveStringContainSeparatorBetweenFieldAndValue($directiveString)) {
            return false;
        }

        return true;
    }
1120696
public function parseXml($xmlString)
    {
        Validate::notNull($xmlString, 'xmlString');
        Validate::isString($xmlString, 'xmlString');
        $categoryXml = simplexml_load_string($xmlString);
        $attributes = $categoryXml->attributes();
        if (!empty($attributes['term'])) {
            $this->term = (string) $attributes['term'];
        }

        if (!empty($attributes['scheme'])) {
            $this->scheme = (string) $attributes['scheme'];
        }

        if (!empty($attributes['label'])) {
            $this->label = (string) $attributes['label'];
        }

        $this->undefinedContent = (string) $categoryXml;
    }
957004
public function registerDirective(DirectiveInterface ...$directives)
    {
        foreach ($directives as $directive) {
            $this->directives[$directive->getKey()] = $directive;

            if ($directive instanceof MultiValueDirectiveInterface) {
                if ($directive instanceof ComplexDirectiveInterface) {
                    $this->values[$directive->getKey()]['default'] = $directive->toArray();
                } elseif ($directive instanceof ScalarDirectiveInterface) {
                    $this->values[$directive->getKey()]['default'] = $directive->getValue();
                }
            } else if ($directive instanceof ScalarDirectiveInterface) {
                $this->values[$directive->getKey()] = $directive->getValue();
            } else {
                $this->values[$directive->getKey()] = $directive->toArray();
            }
        }

        return $this;
    }
1053072
public function has($string)
    {
        $lowercase = strtolower($string);

        if (!parent::has($lowercase) && !JFactory::getLanguage()->hasKey($string))
        {
            if (isset($this->_aliases[$lowercase])) {
                $key = $this->_aliases[$lowercase];
            }
            elseif (substr($string, 0, strlen($this->getPrefix())) === $this->getPrefix()) {
                $key = $string;
            } else {
                //Gets a key from the catalogue and prefixes it
                $key = $this->getPrefix().$this->generateKey($string);
            }

            $result = JFactory::getLanguage()->hasKey($key);
        }
        else $result = true;

        return $result;
    }
242525
private boolean checkDirective(String directive) {
        if (directives.containsKey(directive)) {
            throw new IllegalArgumentException("Duplicate cache-control directive in configuration file");
        } else if (Directive.get(directive) == null) {
            throw new IllegalArgumentException("Missing or incorrect cache-control syntax in the configuration file");
        }
        return true;
    }
919197
public function create(string $directiveName, $definitionNode = null): Directive
    {
        $directive = $this->resolve($directiveName) ?? $this->createOrFail($directiveName);

        return $definitionNode
            ? $this->hydrate($directive, $definitionNode)
            : $directive;
    }
66870
protected function decodeConfiguration($string)
    {
        $config = [];
        $directives = explode($this->directiveSeparator, $string);
        foreach ($directives as $directive) {
            $parts = array_filter(explode($this->sourceSeparator, $directive));
            $key = trim(array_shift($parts));
            $config[$key] = $parts;
        }

        return $config;
    }
1096275
public function apply(&$templateString) {

		$templateString = preg_replace_callback(
			'~<(\w+)\s+(.*?)class=(\'|")?([a-z0-9_]*\s*)shortened_(\d+)(.*?)>(?s)(.*?)(?-s)</\s*\1>~i',
			function($matches) {
				$prefix = sprintf("<%s %sclass=%s%sshortened%s>", $matches[1], $matches[2], $matches[3], $matches[4], $matches[6]);
				$suffix = sprintf("</%s>", $matches[1]);
				$len = (int) $matches[5];
				$src = $matches[7];
				
				if(strlen(strip_tags($src)) <= $len) {
					return $prefix . $src . $suffix;
				}
				
				$ret = substr(strip_tags($src), 0, $len + 1);
				return $prefix . substr($ret,0,strrpos($ret,' ')) . '&hellip;' . $suffix;
			},
			$templateString
		);

	}
1183199
private function persist($match, $subject, $directive, $isstring = false)
	{
		$match = isset($match[1]) ? $match[1] : null;
		$uses = $directive->uses() !== false ? $directive->uses() : null;

		$e = $this->__engine;

		if ($uses !== null && $directive->name() !== false && $this->_control($uses)) {
			return "<?php $uses ((new $subject)->message($match)) : ?>";
		}
		else if ($uses !== null && $directive->name() !== false && $this->_control($uses) === false) {
			return "<?php $uses((new $subject)->message($match)); ?>";
		}
		else if ($directive->name() !== true && $uses === null) {
			return $directive->message($match);
		}
	}
83539
public function detect($string, $inBlock = false)
    {
        if (empty($string)) {
            return (false);
        }
        if (
            substr_compare($string, '[[[', 0, 3) === 0 ||
            substr_compare($string, '<<<', 0, 3) === 0 ||
            substr_compare($string, '{{{', 0, 2) === 0 ||
            substr_compare($string, '||', 0, 2) === 0 ||
            substr_compare($string, '!!', 0, 2) === 0
        )
            return (false);
        if (!preg_match("/^\s*\*{2}.*\*{2}\s*.*$/", $string) &&
            !preg_match("/^\s*#{2}.*#{2}\s*.*$/", $string) &&
            preg_match("/^\s*[\*#\- \t>;=].*/", $string)
        ) {
            return (false);
        }
        $this->_detectMatch = array($string, $string);
        return (true);
    }
476456
private function prepareStepString($keywordsString)
    {
        if (0 === mb_strpos($keywordsString, '*|', 0, 'UTF-8')) {
            $keywordsString = mb_substr($keywordsString, 2, mb_strlen($keywordsString, 'utf8') - 2, 'utf8');
        }

        return $keywordsString;
    }
727915
protected function getSingleArgumentDefinition(): InputValueDefinitionNode
    {
        if (count($this->definitionNode->arguments) !== 1) {
            throw new DirectiveException(
                "The @delete directive requires the field {$this->definitionNode->name->value} to only contain a single argument."
            );
        }

        return $this->definitionNode->arguments[0];
    }
685
public static function fromString(Text $configString)
    {
        $scope = new Scope();
        while (false === $configString->eof()) {

            if (true === $configString->isEmptyLine()) {
                $scope->addPrintable(EmptyLine::fromString($configString));
            }

            $char = $configString->getChar();

            if ('#' === $char) {
                $scope->addPrintable(Comment::fromString($configString));
                continue;
            }

            if (('a' <= $char) && ('z' >= $char)) {
                $scope->addDirective(Directive::fromString($configString));
                continue;
            }

            if ('}' === $configString->getChar()) {
                break;
            }

            $configString->inc();
        }
        return $scope;
    }
966058
public function contains(DirectiveInterface $directive)
    {
        foreach ($this->directives as $existingDirective) {
            if ($directive->equals($existingDirective)) {
                return true;
            }
        }

        return false;
    }
319974
public function detect($string, $inBlock = false)
    {
        if (!preg_match($this->regexp, $string, $this->_detectMatch)) {
            return (0);
        }

        return (1);
    }
976465
public static function parseHeaders($headerString)
	{
		$headers = explode("\n", $headerString);
		$keys = array_keys($headers);
		$regexReturnCode = '/^\S+\s+(\d+)\s?(.*)/';
		$regexHeader = '/^(.*?):\s*(.*)$/';
		$headers['Return-Code'] = preg_match($regexReturnCode, $headerString, $matches)
			? $matches[1]
			: 200;
		foreach ($keys as $k) {
			$v = trim($headers[$k]);
			unset($headers[$k]);
			if (preg_match($regexHeader, $v, $matches)) {
				$k = $matches[1];
				$k = preg_replace_callback('/(^|-)(.?)/', function ($matches) {
					return $matches[1].strtoupper($matches[2]);
				}, $k);
				$v = trim($matches[2]);
				if (isset($headers[$k])) {
					if (!is_array($headers[$k])) {
						$headers[$k] = array($headers[$k]);
					}
					$headers[$k][] = $v;
				} else {
					$headers[$k] = $v;
				}
			} elseif (preg_match($regexReturnCode, $v, $matches)) {
				$headers['Return-Code'] = $matches[1];
			}
		}
		return $headers;
	}
972314
public function validateDirective($d)
    {
        $id = $d->id->toString();
        $this->context[] = "directive '$id'";
        $this->validateId($d->id);

        $this->with($d, 'description')
            ->assertNotEmpty();

        // BEGIN - handled by InterchangeBuilder
        $this->with($d, 'type')
            ->assertNotEmpty();
        $this->with($d, 'typeAllowsNull')
            ->assertIsBool();
        try {
            // This also tests validity of $d->type
            $this->parser->parse($d->default, $d->type, $d->typeAllowsNull);
        } catch (HTMLPurifier_VarParserException $e) {
            $this->error('default', 'had error: ' . $e->getMessage());
        }
        // END - handled by InterchangeBuilder

        if (!is_null($d->allowed) || !empty($d->valueAliases)) {
            // allowed and valueAliases require that we be dealing with
            // strings, so check for that early.
            $d_int = HTMLPurifier_VarParser::$types[$d->type];
            if (!isset(HTMLPurifier_VarParser::$stringTypes[$d_int])) {
                $this->error('type', 'must be a string type when used with allowed or value aliases');
            }
        }

        $this->validateDirectiveAllowed($d);
        $this->validateDirectiveValueAliases($d);
        $this->validateDirectiveAliases($d);

        array_pop($this->context);
    }