<commit_before><?php
/**
 * Global functions.
 *
 * If you're putting something in here you better have a damn good reason and the approval of all other PHP developers on the team.
 */

/**
 * h
 *
 * For outputting strings. Add all sorts of clean methods in here as desired.
 */
function h($text) {
	return htmlspecialchars($text);
}<commit_msg>More string escaping & improves output handling functions<commit_after><?php
/**
 * Global functions.
 *
 * If you're putting something in here you better have a damn good reason and the approval of all other PHP developers on the team.
 */

/**
 * h
 *
 * For outputting strings. Add all sorts of clean methods in here as desired.
 * either takes one arg of text to escape
 * or printf style args where ALL args apart from the formatter are escaped
 * eg. h('<h1>%s</h1><p>%s</p>', $v1, $v2)
 */
function h($text /*args*/) {
	$args = func_get_args();
	if (count($args) == 1) {
		return htmlspecialchars($text);
	} else {
		$args = array_map(function($str) { return htmlspecialchars($str); }, $args);
		$args[0] = $text;
		return call_user_func_array('sprintf', $args);
	}
}

/**
 * hx
 *
 * Outputs stings using h() above unless all the arguments are empty
 * Note pass in args using @ if the variable may be unset (eg hx('<p>%s</p>', @$obj->missing))
 */
function hx($text /*args*/) {
	$args = func_get_args();
	array_shift($args);
	if (join($args) === '') return '';
	array_unshift($args, $text);
	return call_user_func_array('h', $args);
}
{'fraction_non_alphanumeric': 0.14573539288112827, 'fraction_numerical': 0.004029550033579583, 'mean_word_length': 3.966666666666667, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, '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': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5354743', 'n_tokens_mistral': 475, 'n_tokens_neox': 473, 'n_words': 178}