<commit_before><?php
/**
 * Substitute
 *
 * Copyright (c) 2012 <NAME>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright (c) 2012 <NAME>
 * @license The MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

namespace substitute;

/**
 * Substitute template
 *
 * @package substitute
 */
class Template {

	/**
	 * Template body
	 *
	 * @var string
	 */
	protected $body = '';

	/**
	 * Constructor
	 *
	 * @param string $body template body
	 */
	public function __construct($body) {
		$this->body = $body;
	}

	/**
	 * Renders the template using provided vars
	 *
	 * @param array $vars key-value pairs of variables and their values
	 */
	public function render($vars = array()) {
		$delimiter = uniqid();

		$result = $this->body;

		$keys = array_keys($vars);

		foreach ($keys as $key) {
			$result = str_replace("{{$key}}", "{$delimiter}.{$key}.{$delimiter}", $result);
		}

		$search  = array_map(function ($name) use ($delimiter) { return "{$delimiter}.{$name}.{$delimiter}"; }, $keys);
		$replace = array_values($vars);

		return str_replace($search, $replace, $result);
	}
}<commit_msg>D'oh!<commit_after><?php
/**
 * Substitute
 *
 * Copyright (c) 2012 <NAME>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright (c) 2012 <NAME>
 * @license The MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

namespace substitute;

/**
 * Substitute template
 *
 * @package substitute
 */
class Template {

	/**
	 * Template body
	 *
	 * @var string
	 */
	protected $body = '';

	/**
	 * Constructor
	 *
	 * @param string $body template body
	 */
	public function __construct($body) {
		$this->body = $body;
	}

	/**
	 * Renders the template using provided vars
	 *
	 * @param array $vars key-value pairs of variables and their values
	 */
	public function render($vars = array()) {
		$keys = array_keys($vars);
		$vals = array_values($vars);

		$keys = array_map(function ($k) {
			return '{' . $k . '}';
		}, $keys);

		return strtr($this->body, array_combine($keys, $vals));
	}
}
{'fraction_non_alphanumeric': 0.16375344986200552, 'fraction_numerical': 0.007359705611775529, 'mean_word_length': 3.456967213114754, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2343143', 'n_tokens_mistral': 751, 'n_tokens_neox': 673, 'n_words': 192}