Replace conditional placeholders used by Internet Explorer.

@param string                                           $contents
@param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer

@return string
771046
protected function setConditionalCommentsPlaceholder($contents, PlaceholderContainer $placeholderContainer)
    {
        return preg_replace_callback(
            '/
                (
                    <!                  # Match the start of a comment
                    (-{2})?             # IE can understand comments without dashes
                    \[                  # Match the start ("[" is a metachar => escape it)
                        (?:(?!\]>).)*   # Match everything except "]>"
                    \]>                 # Match end
                )
                (
                    (?:
                        (?!<!\[endif\]-{2}?>)
                    .)*
                )                     # Match everything except end of conditional comment
                (
                    <!\[endif\]
                          (?:\2|(?=>))  # Use a trick to ensure that when dashes are captured they are...
                                        # matched at the end! Else make sure that the next char is a ">"!
                    >                   # Match the endif with the captured dashes
                )
            /xis',
            function ($match) use ($placeholderContainer) {
                if (!empty(preg_replace('/\s*/', '', $match[3]))) {
                    return $placeholderContainer->createPlaceholder($match[1]).$match[3].$placeholderContainer->createPlaceholder($match[4]);
                } else {
                    return '';
                }
            }, $contents);
    }
1258463
protected function _getPlaceholder($placeholder = null)
    {
        $ret = $this->_getSetting('placeholder');
        if ($placeholder) {
            return $this->getData()->trlStaticExecute($ret[$placeholder]);
        }
        foreach ($ret as $k => $v) {
            $ret[$k] = $this->getData()->trlStaticExecute($v);
        }
        return $ret;
    }
1311127
public static function parentPlaceholder($section = '')
    {
        if (! isset(static::$parentPlaceholder[$section])) {
            static::$parentPlaceholder[$section] = '##parent-placeholder-'.sha1($section).'##';
        }

        return static::$parentPlaceholder[$section];
    }
1201407
public function replacePlaceholders($string, $values, $quoteIfNecessary = true)
    {
        foreach ($values as $placeholder => $value) {
            $replacement = $quoteIfNecessary ? $this->quoteIfNecessary($value) : $value;
            $string = str_replace(":{$placeholder}", $replacement, $string);
        }

        return $string;
    }
412904
public function _format($format, $placeholders = [], $default = '')
	{
		$placeholders = (array) $placeholders;
		$matches = [];
		if(!preg_match_all('/\{([^{}]*)\}+/u', $format, $matches))
			return sprintf($format, ...array_values($placeholders));

		ksort($placeholders, SORT_NATURAL);
		$placeholders['__default__'] = $default;
		$positions = array_flip(array_keys($placeholders));

		$type_specifiers = '/([sducoxXbgGeEfF])$/u';
		$replacements = [];

		foreach ($matches[1] as $match) {

			list($name, $options) = array_pad(explode(':', $match, 2), 2, '');
			if(!preg_match($type_specifiers, $options))
				$options .= 's';

			$position = array_key_exists($name, $positions)
			? $positions[$name]+1 : $positions['__default__']+1;

			$pattern = '%'.$position.'$'.$options;
			$replacements['{'.$match.'}'] = $pattern;
		}

		$format = str_replace(array_keys($replacements), array_values($replacements), $format);

		return sprintf($format, ...array_values($placeholders));
	}
489779
private function jsPlaceholder($width, $height, $text, $backgroundColor, $textColor, $random, array $options)
    {
        $src = 'holder.js/' . $width . 'x' . $height . '?bg=' . $backgroundColor . '&fg=' . $textColor . '&text=' . $text;

        if ($random) {
            $src .= $src . '&random=yes';
        }

        return Html::img('', array_merge($options, ['data-src' => $src]));
    }
182396
public function restorePlaceholders($contents)
    {
        foreach ($this->all() as $placeholder => $original) {
            $contents = str_replace($placeholder, $original, $contents);
        }

        return $contents;
    }
640941
def escapePlaceholders(self,inputString):
        
        escaped = inputString.replace(MapConstants.placeholder,'\\'+MapConstants.placeholder)
        escaped = escaped.replace(MapConstants.placeholderFileName,'\\'+MapConstants.placeholderFileName)
        escaped = escaped.replace(MapConstants.placeholderPath,'\\'+MapConstants.placeholderPath)
        escaped = escaped.replace(MapConstants.placeholderExtension,'\\'+MapConstants.placeholderExtension)
        escaped = escaped.replace(MapConstants.placeholderCounter,'\\'+MapConstants.placeholderCounter)
        return escaped
269916
protected function replaceAppClass($contents)
    {
        $modified = str_replace(
            'Illuminate\Foundation\Application',
            'Shpasser\GaeSupportL5\Foundation\Application',
            $contents);

        if ($contents !== $modified) {
            $this->myCommand->info('Replaced the application class in "bootstrap/app.php".');
        }

        return $modified;
    }
197268
private function doReplacements($contents)
	{
		// Replace variables
		if (isset($this->replacements) && count($this->replacements) > 0)
		{
			foreach ($this->replacements as $k => $v)
			{
				if (is_array($v))
				{
					foreach ($v as $replacement)
					{
						foreach ($replacement as $key => $value)
						{
							$contents = preg_replace("/%={$key}=%/", $value, $contents, 1);
						}
					}
				}
				else
				{
					// See if there are any instances of our key with special qualifiers
					if (preg_match_all("/%={$k}\+([[:alpha:]]+)=%/", $contents, $matches) && isset($matches[1]))
					{
						// Remove complete match
						unset($matches[0]);
						foreach ($matches[1] as $match)
						{
							switch ($match)
							{
								// Upper case word
								case 'uc':
									$value = strtoupper($v);
									break;
								// Upper case first character
								case 'ucf':
									$value = ucfirst($v);
									break;
								// Upper case first character and plural
								case 'ucfp':
									$value = ucfirst(Inflector::pluralize($v));
									break;
								// Plural form
								case 'p':
									$value = Inflector::pluralize($v);
									break;
							}

							$contents = str_replace("%={$k}+{$match}=%", $value, $contents);
						}
					}

					// Now do all basic replacements
					$contents = str_replace("%={$k}=%", $v, $contents);

					if ($this->doBlindReplacements)
					{
						$contents = str_replace($k, $v, $contents);
					}
				}
			}
		}

		// Now parse for nested templates
		preg_match_all('/\$\^[[:alpha:]\.]*\^\$/', $contents, $matches, PREG_SET_ORDER);

		if (isset($matches) && count($matches) > 0)
		{
			foreach ($matches as $match)
			{
				foreach ($match as $key)
				{
					// Get template contents
					$keyReal = preg_replace('/\$\^([[:alpha:]\.]*)\^\$/', '$1', $key);
					$subPath = __DIR__ . DS . 'Scaffolding' . DS . 'Templates' . DS . $this->getType() . '.' . $keyReal . '.tmpl';

					if (!is_file($subPath))
					{
						continue;
					}

					$subTmpl = file_get_contents($subPath);

					if (isset($this->replacements[$keyReal]) && is_array($this->replacements[$keyReal]))
					{
						$count    = count($this->replacements[$keyReal]);
						$repeat   = str_repeat($key, $count);
						$contents = str_replace($key, $repeat, $contents);
					}

					$contents = str_replace($key, $subTmpl, $contents);
					$contents = $this->doReplacements($contents);
				}
			}
		}

		return $contents;
	}
835412
protected function setCDataPlaceholder($contents, PlaceholderContainer $placeholderContainer)
    {
        return preg_replace_callback('/<!\[CDATA\[((?!\]\]>).)*\]\]>/s', function ($match) use ($placeholderContainer) {
            return $placeholderContainer->createPlaceholder($match[0]);
        }, $contents);
    }
500475
protected function placeholderClb($matches)
    {
        $placeholder = isset($matches[1]) ? $matches[1] : '';
        if (isset($matches[3])) {
            $name = $matches[3];
            if (empty($name)) {
                /* There is a named placeholder without name ("?set:") */
                throw new UnknownPlaceholder($matches[0]);
            }
        } else {
            $name = null;
            if ($placeholder == '?') { // "??" for question mark
                return '?';
            }
        }
        if ($name) {
            if ($this->counter == 0) {
                $this->named = true;
            } elseif (!$this->named) {
                /* There is a named placeholder although already used regular */
                throw new MixedPlaceholder($matches[0]);
            }
            if (!array_key_exists($name, $this->data)) {
                throw new DataNamed($name);
            }
            $value = $this->data[$name];
        } elseif ($this->named) {
            /* There is a regular placeholder although already used named */
            throw new MixedPlaceholder($matches[0]);
        } else {
            if (!array_key_exists($this->counter, $this->data)) {
                /* Data for regular placeholders is ended */
                throw new DataNotEnough(count($this->data), $this->counter);
            }
            $value = $this->data[$this->counter];
        }
        $this->counter++;
        $parser = new ParserPH($placeholder);
        $type = $parser->getType();
        $modifiers = $parser->getModifiers();
        $method = 'replacement'.strtoupper($type);
        return $this->$method($value, $modifiers);
    }
470624
protected function replaceContent($content, $vars = [])
    {
        $find = [];
        $replace =[];
        foreach($vars as $k => $v) {
            $find[] = '#' . $k . '#';
            $replace[] = $v;
        }
        return str_ireplace($find, $replace, $content);
    }
373798
static function ReplaceUsing($placeholder, Interfaces\IRealizer $realizer = null)
    {
        $args = func_get_args();    
        array_shift($args);
        if (count($args) >= 2)
        {
            array_shift($args);   
        }
        return self::ReplaceArgsUsing($placeholder, $realizer, $args);
    }
875426
public function replaceContents($contents)
    {
        preg_match_all('/{{(.*)}}/', $contents, $matches);

        foreach ($matches[0] as $key => $match) {
            if (!empty($match)) {
                if (($resolved = $this->resolveVariable($matches[1][$key])) !== Constants::NOT_RESOLVED) {
                    $contents = str_replace($matches[0][$key], $resolved, $contents);
                }
            }
        }

        return $contents;
    }
1076641
protected function placeholder(&$placeholder)
    {
        if ($this->match(
            $this->utf8
                ? '([\pL\w\-_]+|#[{][$][\pL\w\-_]+[}])'
                : '([\w\-_]+|#[{][$][\w\-_]+[}])',
            $m
        )) {
            $placeholder = $m[1];

            return true;
        }

        return false;
    }
676359
function replacePlaceholders(src, options) {
	return Object.keys(placeholders).reduce((out, placeholder) => {
		return out.replace(new RegExp(`${placeholder}`, 'g'), placeholders[placeholder]);
	}, src);
}