<commit_before><?php 

require 'helpers/viewhelper.php';

class Controller {
	
	public $title = "Presskit";

	protected $view;

	public function __construct(){
		$this->view = new ViewHelper();
	}

	protected function parse($xmlpath){
		libxml_use_internal_errors(true);
		$xml = simplexml_load_file($xmlpath, 'SimpleXMLElement', LIBXML_NOCDATA);

		foreach (libxml_get_errors() as $error) {
			echo '<p>XML Error on line ', $error->line, ' column ', $error->column, ': ', $error->message, '</p>';
		}

		if(!$xml) die();

		return $this->xml2array($xml);
	}

	private static function xml2array ( $xmlObject, $out = array ()) {
		foreach ( (array) $xmlObject as $index => $node ){
			$index = Controller::dashesToCamelCase($index);
			$out[$index] = ( is_object ( $node ) ||  is_array ( $node ) ) ? Controller::xml2array ( $node ) : $node;
		}
		return $out;
	}

	// stolen from: http://stackoverflow.com/questions/2791998/convert-dashes-to-camelcase-in-php
	private static function dashesToCamelCase($string, $capitalizeFirstCharacter = false) {
		$str = str_replace(' ', '', ucwords(str_replace('-', ' ', $string)));

		if (!$capitalizeFirstCharacter) {
			$str[0] = lcfirst($str[0]);
		}

		return $str;
	}
}
?><commit_msg>Trims whitespace off nodes when parsing them<commit_after><?php 

require 'helpers/viewhelper.php';

class Controller {
	
	public $title = "Presskit";

	protected $view;

	public function __construct(){
		$this->view = new ViewHelper();
	}

	protected function parse($xmlpath){
		libxml_use_internal_errors(true);
		$xml = simplexml_load_file($xmlpath, 'SimpleXMLElement', LIBXML_NOCDATA);

		foreach (libxml_get_errors() as $error) {
			echo '<p>XML Error on line ', $error->line, ' column ', $error->column, ': ', $error->message, '</p>';
		}

		if(!$xml) die();

		return $this->xml2array($xml);
	}

	private static function xml2array ( $xmlObject, $out = array ()) {
		foreach ( (array) $xmlObject as $index => $node ){
			$index = Controller::dashesToCamelCase($index);
			$out[$index] = ( is_object ( $node ) ||  is_array ( $node ) ) ? Controller::xml2array ( $node ) : trim($node);
		}
		return $out;
	}

	// stolen from: http://stackoverflow.com/questions/2791998/convert-dashes-to-camelcase-in-php
	private static function dashesToCamelCase($string, $capitalizeFirstCharacter = false) {
		$str = str_replace(' ', '', ucwords(str_replace('-', ' ', $string)));

		if (!$capitalizeFirstCharacter) {
			$str[0] = lcfirst($str[0]);
		}

		return $str;
	}
}
?>
{'fraction_non_alphanumeric': 0.1775813579750904, 'fraction_numerical': 0.009642426677380474, 'mean_word_length': 4.496688741721854, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, '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': '6169948', 'n_tokens_mistral': 935, 'n_tokens_neox': 847, 'n_words': 178}