Manages template strings.

@param mixed $strings
@return mixed
185493
public function strings($strings = null) {
		if (is_array($strings)) {
			return $this->_strings = $this->_strings + $strings;
		}
		if (is_string($strings)) {
			return isset($this->_strings[$strings]) ? $this->_strings[$strings] : null;
		}
		return $this->_strings;
	}
700554
function loadStrings($strings) {
        // Load some commonly used strings
        if (get_string_manager()->string_exists($this->title, 'tool_xmldb')) {
            $this->str['title'] = get_string($this->title, 'tool_xmldb');
        } else {
            $this->str['title'] = $this->title;
        }

        // Now process the $strings array loading it in the $str atribute
        if ($strings) {
            foreach ($strings as $key => $module) {
                $this->str[$key] = get_string($key, $module);
            }
        }
    }
1235430
static function Trim($string, $chars = null)
    {
        self::InitEncoding();
        if (!$chars)
            return trim($string);

        return trim($string, $chars);
    }
1041684
public function translate($string, Array $vars = array())
    {
        // Use custom translator
        if ($this->translator) {
            return $this->translator($this->getString($string), $vars);
        }

        return $this->compileString($this->getString($string), $vars);
    }
53402
public function templates($templates = null)
    {
        deprecationWarning(
            'StringTemplateTrait::templates() is deprecated. ' .
            'Use setTemplates()/getTemplates() instead.'
        );

        if ($templates === null || is_string($templates)) {
            return $this->templater()->get($templates);
        }

        $this->templater()->add($templates);

        return $this;
    }
422965
public static function SetTemplates ($templates = []) {
		if (gettype(static::$templates) == 'array') {
			static::$templates = (array) $templates;
		} else {
			static::$templates = (object) $templates;
		}
		return static::$templates;
	}
1285860
public function removeEvilAttributes(array $strings): self
    {
        $this->_evil_attributes_regex = \array_diff(
            $this->_evil_attributes_regex,
            \array_intersect($strings, $this->_evil_attributes_regex)
        );

        return $this;
    }
827631
public function build(array $strings)
	{
		$strings = array_unique($strings);
		sort($strings);
		if ($this->isEmpty($strings))
		{
			return '';
		}

		$strings = $this->splitStrings($strings);
		$strings = $this->meta->replaceMeta($strings);
		$strings = $this->runner->run($strings);

		return $this->serializer->serializeStrings($strings);
	}
1072005
private function templates(array $templates)
    {
        if ($templates) {
            foreach ($templates as $template) {
                if ($template->getManaged()) {
                    yield $template;
                }
            }

            return;
        }

        foreach ($this->templateManager->findAll() as $template) {
            if ($template->getManaged()) {
                yield $template;
            }
        }
    }
112285
public function process($string)
    {
        preg_match_all($this->tagFilter, $string, $matches);

        if (!$matches) {
            return $string;
        }

        foreach ($matches[0] as $i => $m) {
            if (array_key_exists($matches[1][$i], $this->styles)) {
                $string = $this->replaceColors(
                    $string,
                    $matches[1][$i],
                    $matches[2][$i],
                    $this->styles[$matches[1][$i]]
                );
            } elseif (strpos($matches[1][$i], '=')) {
                // Custom format
                $string = $this->replaceColors(
                    $string,
                    $matches[1][$i],
                    $matches[2][$i],
                    ColorStyle::fromString($matches[1][$i])
                );
            }
        }

        return $string;
    }
1372933
public static function findPrefix($first, ...$strings): string
    {
        if (\is_array($first)) {
            $strings = $first;
            $first = $strings[0];
            unset($strings[0]);
        }

        for ($i = 0, $n = \strlen($first); $i < $n; $i++) {
            foreach ($strings as $s) {
                if (!isset($s[$i]) || $first[$i] !== $s[$i]) {
                    while ($i && $first[$i - 1] >= "\x80" && $first[$i] >= "\x80" && $first[$i] < "\xC0") {
                        $i--;
                    }

                    return \substr($first, 0, $i);
                }
            }
        }

        return $first;
    }
284962
protected function getPrefixLength(array $strings)
	{
		$len = 1;
		$cnt = count($strings[0]);
		while ($len < $cnt && $this->stringsMatch($strings, $len))
		{
			++$len;
		}

		return $len;
	}
1186667
public static function alternator(array $strings)
    {
        return function() use ($strings) {
            static $i = 0;
            $index = $i++ % count($strings);

            return $strings[$index];
        };
    }
719838
final public static function handlifyString($string)
    {
        $string = preg_replace('/\W+/', '_', $string);
        $string = preg_replace('/([A-Z])/', '_$1', $string);
        $string = strtolower($string);
        $string = preg_replace('/_+/', '_', trim($string, '_'));

        return $string;
    }
732036
public function apply(&$templateString) {

		$application	= Application::getInstance();
		$config			= $application->getConfig();

		$locale = $application->getCurrentLocale();

		// without locale replace placeholders with their identifier

		if(empty($locale)) {

			$templateString = preg_replace(
				array(
					'@\{![a-z0-9_]+\}@i',
					'@\{![a-z0-9_]+:(.*?)\}@i'
				),
				array(
					'',
					'$1'
				),
				$templateString
			);
			return;

		}

		$this->getPhrases($locale);

		$templateString = preg_replace_callback(
			'@\{!([a-z0-9_]+)(:(.*?))?\}@i',
			array($this, 'translatePhraseCallback'),
			$templateString
		);
	}
872955
public function addStrings($strings)
    {
        foreach ($strings as $key => $string) {
            $this->addString($key, $string);
        }

        return $this;
    }
430372
protected function normalizeString($string)
    {
        if (false === strpos($string, '_')) {
            return $string;
        }

        $offset = strspn($string, '_');
        if ($offset) {
            $underscorePrefix = substr($string, 0, $offset);
            $string = substr($string, $offset);
        } else {
            $underscorePrefix = '';
        }

        return $underscorePrefix.parent::normalizeString($string);
    }