Replace patterns in the given string and store the replacement

@param  string $js The string to lock

@return bool
194196
protected function lock($js)
	{
		/* lock things like <code>"asd" + ++x;</code> */
		$lock = '"LOCK---' . crc32(time()) . '"';

		$matches = array();
		preg_match('/([+-])(\s+)([+-])/S', $js, $matches);
		if (empty($matches))
		{
			return $js;
		}

		$this->locks[$lock] = $matches[2];

		$js = preg_replace('/([+-])\s+([+-])/S', "$1{$lock}$2", $js);

		/* -- */

		return $js;
	}
1190802
private function _replaceDelimiters ($s)
    {
        foreach ($this->getWordDelimiters() as $delimiter) {
            if ($delimiter == $this->getDelimiterReplacement()) {
                continue;
            }
            if (in_array($delimiter, $this->getNotReplacedChars())) {
                continue;
            }
            
            $s = str_replace($delimiter, $this->getDelimiterReplacement(), $s);
        }
        return $s;
    }
1239024
function js($flush = true) {
        $js = $this->_js;
        if ($flush) $this->_js = [];
        $html = '';
        foreach ($js as $url => $inc) {
            $html .= '<script src="'.$url.'"></script>'.PHP_EOL;
        }
        if (!empty($this->_scripts)) {
            $scripts = $this->_scripts;
            if ($flush) $this->_scripts = [];
            $html .= '<script>'.PHP_EOL;
            foreach ($scripts as $script) {
                $html .= $script . PHP_EOL;
            }
            $html .= '</script>';
        }
        return $html;
    }
325567
protected function replace(array &$str, $pattern, $replacement)
    {
        foreach ($str as &$s) {
            $s = preg_replace($pattern, $replacement, $s);
        }
    }
1373512
public static function compress($js)
    {
        $js = (string) $js;
        try {
            $js_minifier = new static($js);
            $minified_js = $js_minifier->min();
            return $minified_js;
        } catch (\Exception $exception) {
            return $js;
        }
    }
1106465
function replace(string, pattern, replacement) {
    var isReplaced = false;

    var result = string.replace(pattern, function () {
      isReplaced = true;

      // arguments are $0, $1, ..., offset, string
      return Array.prototype.slice.call(arguments, 1, -2)
        .reduce(function (pattern, match, index) {
          // '$1' from strings like '$11 $12' shouldn't be replaced.
          return pattern.replace(
            new RegExp('\\$' + (index + 1) + '(?=[^\\d]|$)', 'g'),
            match
          );
        }, replacement);
    });

    if (!isReplaced) {
      throw new Error(
        format(
          'we couldn\'t replace pattern: \'%s\' with value: \'%s\' ' +
          'in file: \'%s\'',
          pattern, replacement, path
        )
      );
    }
    return result;
  }
606169
public function escapeJs($js)
    {
        $js = $this->toUtf8($js);
        
        if ($js === '' || ctype_digit($js)) {
            return $js;
        }

        $result = preg_replace_callback('/[^a-z0-9,\._]/iSu', $this->jsMatcher, $js);
        
        return $this->fromUtf8($result);
    }
998407
public function run(JsUtils $js){
		if(!isset($this->_bsComponent)){
			if(isset($this->close)){
				$js->execOn("click", "#".$this->identifier." .close", "$(this).closest('.message').transition({$this->_closeTransition})");
			}
			if(isset($this->_timeout)){
				$js->exec("setTimeout(function() { $('#{$this->identifier}').transition({$this->_closeTransition}); }, {$this->_timeout});",true);
			}
		}
		return parent::run($js);
	}
813854
public function replace($patternName, Siteroot $siteroot, ElementVersion $elementVersion, $language)
    {
        if (!isset($this->patterns[$patternName])) {
            $pattern = '%p';
        } else {
            $pattern = $this->patterns[$patternName];
        }

        return $this->replacePattern($pattern, $siteroot, $elementVersion, $language);
    }
214927
public function bind($js)
    {
        foreach ($this->views as $view) {
            $this->event->listen("composing: {$view}", function () use ($js) {
                echo "<script>{$js}</script>";
            });
        }
    }
962946
public static function strFindAndReplaceAll($vars = array(), $str)
    {
        if (array_count_values($vars) > 0){
            foreach ($vars as $key => $val) {
                for ($i = substr_count($str, $key); $i > 0; $i--) {
                    $str = \WebCMS\Helpers\SystemHelper::strlReplace($key, $val, $str);
                }
            }
        }
        return $str;
    }
619741
function replacer(str, obj) {
        if (!str || !obj) {
          return;
        }
        if (obj) {
          for (var key in obj) {
            if (str) {
              str = str.split('${' + key + '}').join(obj[key]);
            }
          }
        }
        return str;
      }
604573
public static function replace($text, array $replacements = [], $prefix = '{', $suffix = '}')
    {
        $replacements = static::prepareBinding($replacements, $prefix, $suffix);

        $filter = function ($text) use ($replacements) {
            return strtr($text, $replacements);
        };

        if (is_array($text)) {
            $text = array_map($filter, $text);
        } else {
            $text = $filter($text);
        }

        return $text;
    }
1194470
function searchAndReplace( $search, $replace, $limit, $offset, $orderby, $save = false ) {
		// escape potential backreferences when not in regex mode
		if ( ! $this->regex ) {
			$replace = str_replace( '\\', '\\\\', $replace );
			$replace = str_replace( '$', '\\$', $replace );
		}
		$this->replace = $replace;
		$results = $this->searchForPattern( $search, $limit, $offset, $orderby );
		if ( is_array( $results ) && $save ) {
			$this->replace( $results );
		}
		return $results;
	}
492391
private function replace_string($matches)
    {
        $match = $matches[0];
        $quote = substr($match, 0, 1);
        // Must use addcslashes in PHP to avoid parsing of backslashes
        $match = addcslashes($this->str_slice($match, 1, -1), '\\');

        // maybe the string contains a comment-like substring?
        // one, maybe more? put'em back then
        if (($pos = $this->index_of($match, self::COMMENT)) >= 0) {
            for ($i = 0, $max = count($this->comments); $i < $max; $i++) {
                $match = preg_replace('/' . self::COMMENT . $i . '___/', $this->comments[$i], $match, 1);
            }
        }

        // minify alpha opacity in filter strings
        $match = preg_replace('/progid\:DXImageTransform\.Microsoft\.Alpha\(Opacity\=/i', 'alpha(opacity=', $match);

        $this->preserved_tokens[] = $match;

        return $quote . self::TOKEN . (count($this->preserved_tokens) - 1) . '___' . $quote;
    }
783692
protected function replacePattern($pattern) {
    $replace = array(
      '$DIR' => dirname($this->configFile),
      '$CWD' => getcwd(),
    );
    return str_replace(array_keys($replace), array_values($replace), $pattern);
  }
959065
protected function replace($string)
    {
        foreach ($this->patterns as $key => $value) {
            $string = str_replace($key, $value, $string);
        }

        return $string;
    }