<commit_before><?php
namespace Everyman\Neo4j\Cypher;

use Everyman\Neo4j\Client;

/**
 * Assembles strings from strings with '?' placeholders and 
 * a list of variables.
 */
class QueryAssembler
{

	public function assembleQuery($args)
	{
		$template = array_shift($args);
		if(count($args) > 0) {
			return $this->injectVariables($template, $args);
		} else {
			// No variables to substitute
			return $template;
		}
	}
	
	/**
	 * Slow and naive template parser & replacer.
	 */
	protected function injectVariables($template, $vars) {
		# Parser state
		$escaped = false;
		$doubleQuoted = false;
		$singleQuoted = false;
		
		# Output
		$query = array();
		
		for($i=0,$l=strlen($template);$i<$l;$i++) {
			$char = $template[$i];
			
			if ($char==='?' && !$escaped && !$doubleQuoted && !$singleQuoted) {
				array_push($query, 
				           $this->formatQueryVariable(array_shift($vars)));
				continue;
		    }
		    
	    	array_push($query, $char);
		    
		    switch($char) {
				case '\\':
					$escaped = !$escaped;
					break;
				case '"':
					if(!$escaped && !$singleQuoted) {
						$doubleQuoted = !$doubleQuoted;
					}
					$escaped = false;
					break;
				case '\'':
					if(!$escaped && !$doubleQuoted) {
						$singleQuoted = !$singleQuoted;
					}
					$escaped = false;
					break;
				default: 
					$escaped = false;
					break;
			}
		}
		
		return implode($query);<commit_msg>Fixed messed up indentation in QueryAssembler.<commit_after><?php
namespace Everyman\Neo4j\Cypher;

use Everyman\Neo4j\Client;

/**
 * Assembles strings from strings with '?' placeholders and 
 * a list of variables.
 */
class QueryAssembler
{

	public function assembleQuery($args)
	{
		$template = array_shift($args);
		if(count($args) > 0) {
			return $this->injectVariables($template, $args);
		} else {
			// No variables to substitute
			return $template;
		}
	}
	
	/**
	 * Slow and naive template parser & replacer.
	 */
	protected function injectVariables($template, $vars) {
		# Parser state
		$escaped = false;
		$doubleQuoted = false;
		$singleQuoted = false;
		
		# Output
		$query = array();
		
		for($i=0,$l=strlen($template);$i<$l;$i++) {
			$char = $template[$i];

			if ($char==='?' && !$escaped && !$doubleQuoted && !$singleQuoted) {
				array_push($query, 
				$this->formatQueryVariable(array_shift($vars)));
				continue;
			}

			array_push($query, $char);

			switch($char) {
				case '\\':
					$escaped = !$escaped;
					break;
				case '"':
					if(!$escaped && !$singleQuoted) {
						$doubleQuoted = !$doubleQuoted;
					}
					$escaped = false;
					break;
				case '\'':
					if(!$escaped && !$doubleQuoted) {
						$singleQuoted = !$singleQuoted;
					}
					$escaped = false;
					break;
				default: 
					$escaped = false;
					break;
			}
		}

		return implode($query);
{'fraction_non_alphanumeric': 0.1632290184921764, 'fraction_numerical': 0.002844950213371266, 'mean_word_length': 2.8220108695652173, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7310694', 'n_tokens_mistral': 1247, 'n_tokens_neox': 965, 'n_words': 196}