<commit_before><?php
/**
 * Various utility classes and global functions.
 *
 * @author <NAME>, 2008-2011
 * @author <NAME>, 2012
 * @since 0.1.0
 * @package TestSwarm
 */

	// Protect against web entry
	if ( !defined( 'SWARM_ENTRY' ) ) {
		exit;
	}

	/**
	 * TestSwarm exception
	 * Just a placeholder for now, can be expanded further in the future.
	 *
	 * @since 1.0.0
	 */
	class SwarmException extends Exception {

	}

	/**
	 * Utility function for formatting HTML.
	 * @since 1.0.0
	 *
	 * @param $tagName string: HTML tag name
	 * @param #attribs array: Key/value pairs, unescaped
	 * @param $content string|null: [optional] Text content, to be escaped.
	 */
	function html_tag_open( $tagName, Array $attribs = array() ) {
		$html = "<$tagName";
		foreach ( $attribs as $key => $value ) {
			$html .= ' ' . strtolower( $key ) . '="' . strtr( $value, array(
				'&' => '&amp;',
				'"' => '&quot;',
				"\n" => '&#10;',
				"\r" => '&#13;',
				"\t" => '&#9;',
			) ) . '"';
		}
		$html .= ">";
		return $html;
	}
	function html_tag( $tagName, Array $attribs = array(), $content = "" ) {
		static $voidElements = array(
			'area',
			'base',
			'br',
			'col',
			'command',
			'embed',
			'hr',
			'img',
			'input',
			'keygen',
			'link',
			'meta',
			'param',
			'source',
		);

		$html = html_tag_open( $tagName, $attribs );

		if ( !in_array( $tagName, $voidElements ) ) {
			$content = strtr( $content, array(
				'&' => '&amp;',
				'<' => '&lt;',
			) );
			$html .= "$content</$tagName>";
		}

		return $html;
	}

	/**
	 * Utility function to overwrite keys and support multiple levels.
	 * (array_merge overwrites keys, but isn't recursive. array_merge_recursive
	 * is recurive but doesn't overwrite deper level's keys..)
	 *
	 * @since 0.1.0
	 * @param $arr1 array: Starting point
	 * @param $arr2 array: Used to extend
	 * @param $options array: one or more of 'add', 'overwrite'.
	 * Defaults to array( 'add', 'overwrite' ); If neither is given, the function
	 * will effectively be a no-op.
	 */
	function array_extend( $arr1, $arr2, $options = null ) {
		$options = is_array( $options ) ? $options : array( 'add', 'overwrite' );

		foreach ( $arr2 as $key => $val ) {
			if ( array_key_exists( $key, $arr1 ) && in_array( 'overwrite', $options ) ) {
				if ( is_array( $val ) ) {
					$arr1[$key] = array_extend( $arr1[$key], $arr2[$key], $options );
				} else {
					$arr1[$key] = $val;
				}
			} elseif ( !array_key_exists( $key, $arr1 ) && in_array( 'add', $options ) ) {
					$arr1[$key] = $val;
			}
		}
		return $arr1;
	}

	/**
	 * SQL query utility function
	 * @since 0.1.0
	 * @source php.net/mysql-query#86447
	 */
	function mysql_queryf(/* $string, $arg, .. */) {
		global $swarmContext;

		$args = func_get_args();
		$sql_query = call_user_func_array( 'str_queryf', $args );

		$result = $swarmContext->getDB()->query( $sql_query );
		if (!$result) {
			echo "Invalid query: " . mysql_error();
			exit;
		}

		return $result;
	}
	function str_queryf($string) {
		$args = func_get_args();
		array_shift($args);
		$len = strlen($string);
		$sql_query = "";
		$args_i = 0;<commit_msg>rm mysql_queryf utility, no longer used<commit_after><?php
/**
 * Various utility classes and global functions.
 *
 * @author <NAME>, 2008-2011
 * @author <NAME>, 2012
 * @since 0.1.0
 * @package TestSwarm
 */

	// Protect against web entry
	if ( !defined( 'SWARM_ENTRY' ) ) {
		exit;
	}

	/**
	 * TestSwarm exception
	 * Just a placeholder for now, can be expanded further in the future.
	 *
	 * @since 1.0.0
	 */
	class SwarmException extends Exception {

	}

	/**
	 * Utility function for formatting HTML.
	 * @since 1.0.0
	 *
	 * @param $tagName string: HTML tag name
	 * @param #attribs array: Key/value pairs, unescaped
	 * @param $content string|null: [optional] Text content, to be escaped.
	 */
	function html_tag_open( $tagName, Array $attribs = array() ) {
		$html = "<$tagName";
		foreach ( $attribs as $key => $value ) {
			$html .= ' ' . strtolower( $key ) . '="' . strtr( $value, array(
				'&' => '&amp;',
				'"' => '&quot;',
				"\n" => '&#10;',
				"\r" => '&#13;',
				"\t" => '&#9;',
			) ) . '"';
		}
		$html .= ">";
		return $html;
	}
	function html_tag( $tagName, Array $attribs = array(), $content = "" ) {
		static $voidElements = array(
			'area',
			'base',
			'br',
			'col',
			'command',
			'embed',
			'hr',
			'img',
			'input',
			'keygen',
			'link',
			'meta',
			'param',
			'source',
		);

		$html = html_tag_open( $tagName, $attribs );

		if ( !in_array( $tagName, $voidElements ) ) {
			$content = strtr( $content, array(
				'&' => '&amp;',
				'<' => '&lt;',
			) );
			$html .= "$content</$tagName>";
		}

		return $html;
	}

	/**
	 * Utility function to overwrite keys and support multiple levels.
	 * (array_merge overwrites keys, but isn't recursive. array_merge_recursive
	 * is recurive but doesn't overwrite deper level's keys..)
	 *
	 * @since 0.1.0
	 * @param $arr1 array: Starting point
	 * @param $arr2 array: Used to extend
	 * @param $options array: one or more of 'add', 'overwrite'.
	 * Defaults to array( 'add', 'overwrite' ); If neither is given, the function
	 * will effectively be a no-op.
	 */
	function array_extend( $arr1, $arr2, $options = null ) {
		$options = is_array( $options ) ? $options : array( 'add', 'overwrite' );

		foreach ( $arr2 as $key => $val ) {
			if ( array_key_exists( $key, $arr1 ) && in_array( 'overwrite', $options ) ) {
				if ( is_array( $val ) ) {
					$arr1[$key] = array_extend( $arr1[$key], $arr2[$key], $options );
				} else {
					$arr1[$key] = $val;
				}
			} elseif ( !array_key_exists( $key, $arr1 ) && in_array( 'add', $options ) ) {
					$arr1[$key] = $val;
			}
		}
		return $arr1;
	}

	/**
	 * SQL query utility function
	 * @since 0.1.0
	 * @source php.net/mysql-query#86447
	 */
	function str_queryf($string) {
		$args = func_get_args();
		array_shift($args);
		$len = strlen($string);
		$sql_query = "";
		$args_i = 0;
{'fraction_non_alphanumeric': 0.19038008745375043, 'fraction_numerical': 0.017154389505549948, 'mean_word_length': 2.9410205434062293, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 31, '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': '3901393', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2175, 'n_words': 572}