Parse string to formatted output.

@param string                                 $string
@param array                                  $values
@param \Laranix\Support\IO\Str\Settings|array $options

@return string
198607
public static function format(string $string, array $values, $options = null) : string
    {
        if ($options instanceof Settings) {
            $settings = $options;
        } elseif (is_array($options)) {
            $settings = new Settings($options);
        } else {
            $settings = new Settings();
        }

        $settings->hasRequiredSettings();

        return self::parseString($string, $values, $settings);
    }
619248
public function toString($value, $type, array $options)
    {
        return $this->convert($value, $type, $options, $this->getToStringCallbacks());
    }
814666
public static function parseString($string)
    {
        $groups = [];

        $index = 0;

        $matchSection = false;

        foreach (explode(PHP_EOL, $string) as $line) {
            $line = trim($line);

            if ('' == $line || starts_with($line, '#')) {
                continue;
            }

            // Keys and values may get separated via an equals, so we'll parse them both
            // out here and hang onto their values. We will also lower case this keys
            // and unquotes the values so they are properly formatted for next use.
            if (preg_match('/^\s*(\S+)\s*=(.*)$/', $line, $match)) {
                $key = strtolower($match[1]);

                $value = self::unquote($match[2]);
            }

            // Keys and values may also get separated via a space, so we will parse them
            // out here and hang onto their values. We will also lower case this keys
            // and unquotes the values so they are properly formatted for next use.
            else {
                $segments = preg_split('/\s+/', $line, 2);

                $key = strtolower($segments[0]);

                $value = self::unquote($segments[1]);
            }

            // The configuration file contains sections separated by Host and / or Match
            // specifications. Therefore, if we come across a Host keyword we start a
            // new group. If it's a Match we ignore declarations until next 'Host'.
            if ('host' === $key) {
                $index++;

                $matchSection = false;
            } elseif ('match' === $key) {
                $matchSection = true;
            }

            if (! $matchSection) {
                $groups[$index][$key] = $value;
            }
        }

        return new self(array_values($groups));
    }
162895
public function parseString($string)
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string');
        
        foreach ($this->data as $key => $value) {
            $string = str_replace($key, $value, $string);
        }

        return $string;
    }
1112811
public static function startsWith(string $string, $values): bool
    {
        foreach ((array) $values as $value) {
            if (!strncmp($string, $value, strlen($value))) {
                return true;
            }
        }

        return false;
    }
957584
public static function parseString($string)
    {
        $array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n"));
        if (strpos($string, ':')) {
            $value = [];
            foreach ($array as $val) {
                list($k, $v) = explode(':', $val);
                $value[$k] = $v;
            }
        } else {
            $value = $array;
        }
        
        return $value;
    }
1217040
public static function toQueryString($options = array())
    {
        $temp = array();
        uksort($options, 'strnatcasecmp');
        foreach ($options as $key => $value) {
            if (is_string($key) && !is_array($value)) {
                $temp[] = rawurlencode($key) . '=' . rawurlencode($value);
            }
        }
        return implode('&', $temp);
    }
775418
protected function parseOption($optionString)
    {
        $optionParts = explode('=', $optionString);

        if (count($optionParts) > 1) {
            list($key, $value) = $optionParts;
        } else {
            $key   = $optionString;
            $value = true;
        }

        $this->options[$key] = $value;
        return $this;
    }
573913
public static function renderString($string, array $parameters)
    {
        $replacer = static function ($match) use ($parameters) {
            return $parameters[$match[1]] ?? $match[0];
        };

        return preg_replace_callback('/{{\s*(.+?)\s*}}/', $replacer, $string);
    }
245367
public function parse($string, array $vars = [])
    {
        $output = $string;

        if(is_file($string)) {
            $output = file_get_contents($string);
        }

        if($this->count()) {
            foreach($this->registry as $adapter) {
                if($adapter instanceof Abstracts\AbstractAdapter) {
                    if($adapter->isSupported()) {
                        $adapter->initialize();
                        $adapter->loadString($output);
                        $output = $adapter->parse($vars);
                    }
                }
            }
        }

        return $output;
    }
1265451
private function resolveOptions($string, array $options)
    {
        foreach ($options as $key => $value) {
            $string = str_replace(':' . $key, $value, $string);
        }

        return $string;
    }
1363663
public static function convert($value, $options = self::VAR_STRING)
    {
        $options = (int)$options;

        if ($options & self::VAR_STRING && !empty($value)) {
            return trim(Filter::stripQuotes($value));
        }

        if ($options & self::VAR_FLOAT) {
            return Filter::float($value, 12);
        }

        if ($options & self::VAR_INT) {
            return Filter::int($value);
        }

        if ($options & self::VAR_BOOL || $options & self::VAR_NULL) {
            if (null === $value || 'null' === strtolower(trim($value))) {
                return null;
            }

            return Filter::bool($value);
        }

        return (string)$value;
    }
1159029
public static function parse($string, array $styles)
    {
        // style the entire string if no tags are found
        if (false === strpos($string, '{')) {
            return self::style($string, reset($styles));
        }

        $i = 0;

        // loop through each tag in the string
        while (false !== $openTag = strpos($string, '{')) {
            $style = array_key_exists($i, $styles) ? $styles[$i] : end($styles);

            $escapeSequence = ($style instanceof Style) ? $style->getEscapeSequence() : self::getEscapeSequence($style);
            $resetSequence = ($style instanceof Style) ? Style::getResetSequence() : self::getResetSequence($style);

            // replace opening tag
            $string = substr_replace($string, $escapeSequence, $openTag, 1);

            if (false === $closeTag = strpos($string, '}')) {
                $closeTag = strlen($string);
            }

            // don't produce multiple identical reset tags next to each other
            if (substr($string, $closeTag - strlen($resetSequence), strlen($resetSequence)) !== $resetSequence) {
                $string = substr_replace($string, $resetSequence, $closeTag, 1);
            }

            $i++;
        }

        return $string;
    }
201631
protected function parse_vars($string)
	{
		foreach ($this->vars as $var => $val)
		{
			$string = str_replace("%$var%", $val, $string);
		}

		return $string;
	}
1339199
public function parseString($string)
    {
        $string = (string) $string;
        $string = preg_replace_callback("/\\$\{(.*?)\}/",
            function ($k) {
                return $this->get($k[1]);
            }, $string);

        return $string;
    }
1117436
public function parseString($string, $values)
    {
        $positions = [];
        $pos = 0;
        $offset = 0;

        while (($pos = strpos($string, "?", $offset)) !== false) {
            $positions[] = $pos;
            $offset = $pos + 1;
        }

        $count = count($positions);

        if ($count == 1) {
            $values = array($values);
        }

        for ($i = 0; $i < $count; $i++) {
            $value = $values[$i];
            if ($value instanceof Query) {
                $value = $this->parseValueQuery($value);
            } elseif (is_array($value)) {
                foreach ($value as $key => $subvalue) {
                    if (trim($subvalue) != '') {
                        $value[$key] = is_numeric($subvalue) ? $subvalue : $this->getQuery()->getManager()->getAdapter()->quote($subvalue);
                    } else {
                        unset($value[$key]);
                    }
                }
                $value = "(" . implode(", ", $value) . ")";
            } elseif (is_numeric($value)) {
            } else {
                $value = $this->getQuery()->getManager()->getAdapter()->quote($values[$i]);
            }
            $string = substr_replace($string, $value, strpos($string, '?'), 1);
        }

        return $string;
    }
552828
public function translate($string, array $args = [], array $options = [])
    {
        $translation = new TranslationManager(new LanguageDefault([]));

        return new TranslatableMarkup($string, $args, $options, $translation);
    }