<commit_before><?php
namespace Niysu\Filters;

/**
 * Send CSV data to the response.
 *
 * @copyright 	2012 <NAME> <<EMAIL>>
 * @license 	MIT http://opensource.org/licenses/MIT
 * @link 		http://github.com/Tomaka17/niysu
 */
class CSVResponseFilter extends \Niysu\HTTPResponseFilterInterface {
	public function __construct(\Niysu\HTTPResponseInterface $next) {
		parent::__construct($next);
		$this->setHeader('Content-Type', 'text/csv');
	}

	/**
	 * Turns an 2D-array into a CSV string.
	 *
	 * The $csv parameter must be an array of rows.
	 * Each row must be an array of columns.
	 *
	 * @param array 	$csv 			2D array representing CSV
	 * @param string 	$separator		The separator to use
	 * @return string
	 */
	public function toString($csv, $separator = ';') {
		$fp = fopen('php://memory', 'r+');
		foreach ($csv as $row)
			fputcsv($fp, $row, $separator);
		rewind($fp);
		$csv = stream_get_contents($fp);
		fclose($fp);
		return $csv;
	}

	/**
	 * Adds a row to the CSV data that will be answered.
	 *
	 * @param array 	$csv 			Array of strings representing the row
	 * @param string 	$separator		The separator to use
	 */
	public function addCSVRow($row, $separator = ';') {
		$fp = fopen('php://memory', 'r+');
		fputcsv($fp, $row, $separator);
		rewind($fp);
		$csv = stream_get_contents($fp);
		fclose($fp);
		$this->data .= $csv;
	}

	/**
	 * Sets the CSV data to send when the response is sent.
	 *
	 * See toString for the format to use.
	 *
	 * @param array 	$csv 		Data representing CSV
	 * @param string 	$separator		The separator to use
	 */
	public function setCSVData($csv, $separator = ';') {
		$this->data = $this->toString($csv, $separator);
	}

	public function flush() {
		parent::appendData($this->data);
		parent::flush();
	}


	private $data;
};

?><commit_msg>Minor change in CSVResponseFilter<commit_after><?php
namespace Niysu\Filters;

/**
 * Send CSV data to the response.
 *
 * @copyright 	2012 <NAME> <<EMAIL>>
 * @license 	MIT http://opensource.org/licenses/MIT
 * @link 		http://github.com/Tomaka17/niysu
 */
class CSVResponseFilter extends \Niysu\HTTPResponseFilterInterface {
	public function __construct(\Niysu\HTTPResponseInterface $next) {
		parent::__construct($next);
		$this->setHeader('Content-Type', 'text/csv');
	}

	/**
	 * Turns an 2D-array into a CSV string.
	 *
	 * The $csv parameter must be an array of rows.
	 * Each row must be an array of columns.
	 *
	 * @param array 	$csv 			2D array representing CSV
	 * @param string 	$separator		The separator to use
	 * @return string
	 */
	public function toString($csv, $separator = ';') {
		$fp = fopen('php://memory', 'r+');
		foreach ($csv as $row)
			fputcsv($fp, $row, $separator);
		rewind($fp);
		$csv = stream_get_contents($fp);
		fclose($fp);
		return $csv;
	}

	/**
	 * Adds a row to the CSV data that will be answered.
	 *
	 * @param array 	$csv 			Array of strings representing the row
	 * @param string 	$separator		The separator to use
	 */
	public function addCSVRow($row, $separator = ';') {
		$fp = fopen('php://memory', 'r+');
		fputcsv($fp, $row, $separator);
		rewind($fp);
		$csv = stream_get_contents($fp);
		fclose($fp);
		$this->data .= $csv;
	}

	/**
	 * Sets the CSV data to send when the response is sent.
	 *
	 * See toString for the format to use.
	 *
	 * @param array 	$csv 		Data representing CSV
	 * @param string 	$separator		The separator to use
	 */
	public function setCSVData($csv, $separator = ';') {
		$this->data = $this->toString($csv, $separator);
	}

	public function appendData($data) {
	}

	public function flush() {
		parent::appendData($this->data);
		parent::flush();
	}


	private $data;
};

?>
{'fraction_non_alphanumeric': 0.14688818565400844, 'fraction_numerical': 0.004219409282700422, 'mean_word_length': 2.9305699481865286, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '3855901', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1237, 'n_words': 360}