<commit_before><?php

function getFilePathHash($inputString) {
	return str_pad(dechex(crc32($inputString)), 8, "0", STR_PAD_LEFT) . str_pad(strlen($inputString), 3, "0", STR_PAD_LEFT);
}

function sortHelper($string1,$string2){
	return strlen($string2) - strlen($string1);
}

function remU($input){
	return trim(preg_replace("!\s+!", " ", str_replace("_", " ", $input)));
}

function fixCaseSensitivity($input){
	if(strtolower($input) == $input) {
		return ucwords($input);
	}
	if(strtoupper($input) == $input && strlen($input)>3) {
		return ucwords(strtolower($input));
	}
	return $input;
}

function timeStringToSeconds($time) {
	$sec = 0;
	foreach (array_reverse(explode(":", $time)) as $key => $value) {
		$sec += pow(60, $key) * $value;
	}
	return $sec;
}

function cleanSearchterm($searchterm) {
	# TODO: use flattenWhitespace() in albummigrator on reading tag-information
	return flattenWhitespace(
		str_replace(["_", "-", "/", " ", "(", ")"], " ", $searchterm)
	);
}

function addStars($searchterm) {
	$str = "*" . str_replace(["_", "-", "/", " ", "(", ")"], "* *", $searchterm) . "*";
	// single letters like "o" in "typo o negative" must not get a star appended because the lack of results 
	if(preg_match("/\ ([A-Za-z]){1}\*/", $str, $matches)) {
		$str = str_replace(
			" ".$matches[1]."*",
			" ".$matches[1],
			$str
		);
	}
	return $str;
}

/**
 * Builds querystring to use for sphinx-queries
 * we have to make sure that /autocomplete and /search* gives us the same results
 * @param array $terms : array with searchphrases
 * @return string : query syntax which can be used in MATCH(:match)
 */
function getSphinxMatchSyntax(array $terms) {
	$groups = [];
	foreach($terms as $term) {
		$groups[] = "(' \"". addStars($term) . "\"')";
		$groups[] = "('\"". $term ."\"')";
		$groups[] = "('\"". str_replace(" ", "*", $term) ."\"')";
		$groups[] = "('\"". str_replace(" ", ",", $term) ."\"')";
		$groups[] = "('\"". str_replace(" ", " | ", $term) ."\"')";
		$groups[] = "('\"". str_replace(" ", "* | ", $term) ."*\"')";
	}
	return join("|\n", $groups);
}

/**
 * limit displayed pages in paginator in case we have enourmous numbers
 * @param int $currentPage : currentPage
 * @return int : pages to be displayed
 */
function paginatorPages($currentPage) {
	switch(strlen($currentPage)) {
		case "5": return 5;
		case "4": return 6;
		case "3": return 7;
		default:  return 10;
	}
}

function removeStars($searchterm) {
	return trim(str_replace("*", " ", $searchterm));
}

/**
 * replaces multiple whitespaces with a single whitespace
 */
function flattenWhitespace($input) {
	return preg_replace("!\s+!", " ", $input);
}

/**
 * @return string : empty string or get-parameter-string which is needed for Slim redirects 
 */
function getNoSurSuffix($prefixQuestionmark = TRUE) {
	return (\Slim\Slim::getInstance()->request->get("nosurrounding") == 1)
		? (($prefixQuestionmark)? "?":"") . "nosurrounding=1"
		: "";
}

function notifyJson($message, $type="info") {
	$out = new stdClass();
	$out->notify = 1;
	$out->message = $message;
	$out->type = $type;
	deliverJson($out);
}

function deliverJson($data) {
	$newResponse = \Slim\Slim::getInstance()->response();
	$newResponse->body(json_encode($data));
	$newResponse->headers->set('Content-Type', 'application/json');
	return $newResponse;
}
<commit_msg>added function unifyBraces()<commit_after><?php

function getFilePathHash($inputString) {
	return str_pad(dechex(crc32($inputString)), 8, "0", STR_PAD_LEFT) . str_pad(strlen($inputString), 3, "0", STR_PAD_LEFT);
}

function sortHelper($string1,$string2){
	return strlen($string2) - strlen($string1);
}

function remU($input){
	return trim(preg_replace("!\s+!", " ", str_replace("_", " ", $input)));
}

function fixCaseSensitivity($input){
	if(strtolower($input) == $input) {
		return ucwords($input);
	}
	if(strtoupper($input) == $input && strlen($input)>3) {
		return ucwords(strtolower($input));
	}
	return $input;
}

function timeStringToSeconds($time) {
	$sec = 0;
	foreach (array_reverse(explode(":", $time)) as $key => $value) {
		$sec += pow(60, $key) * $value;
	}
	return $sec;
}

function cleanSearchterm($searchterm) {
	# TODO: use flattenWhitespace() in albummigrator on reading tag-information
	return flattenWhitespace(
		str_replace(["_", "-", "/", " ", "(", ")"], " ", $searchterm)
	);
}

function addStars($searchterm) {
	$str = "*" . str_replace(["_", "-", "/", " ", "(", ")"], "* *", $searchterm) . "*";
	// single letters like "o" in "typo o negative" must not get a star appended because the lack of results 
	if(preg_match("/\ ([A-Za-z]){1}\*/", $str, $matches)) {
		$str = str_replace(
			" ".$matches[1]."*",
			" ".$matches[1],
			$str
		);
	}
	return $str;
}

/**
 * Builds querystring to use for sphinx-queries
 * we have to make sure that /autocomplete and /search* gives us the same results
 * @param array $terms : array with searchphrases
 * @return string : query syntax which can be used in MATCH(:match)
 */
function getSphinxMatchSyntax(array $terms) {
	$groups = [];
	foreach($terms as $term) {
		$groups[] = "(' \"". addStars($term) . "\"')";
		$groups[] = "('\"". $term ."\"')";
		$groups[] = "('\"". str_replace(" ", "*", $term) ."\"')";
		$groups[] = "('\"". str_replace(" ", ",", $term) ."\"')";
		$groups[] = "('\"". str_replace(" ", " | ", $term) ."\"')";
		$groups[] = "('\"". str_replace(" ", "* | ", $term) ."*\"')";
	}
	return join("|\n", $groups);
}

/**
 * limit displayed pages in paginator in case we have enourmous numbers
 * @param int $currentPage : currentPage
 * @return int : pages to be displayed
 */
function paginatorPages($currentPage) {
	switch(strlen($currentPage)) {
		case "5": return 5;
		case "4": return 6;
		case "3": return 7;
		default:  return 10;
	}
}

function removeStars($searchterm) {
	return trim(str_replace("*", " ", $searchterm));
}

/**
 * replaces multiple whitespaces with a single whitespace
 */
function flattenWhitespace($input) {
	return preg_replace("!\s+!", " ", $input);
}

/**
 * replaces curly+square braces with normal braces
 */
function unifyBraces($input) {
	return str_replace(
		["[", "]","{", "}"],
		["(", ")","(", ")"],
		$input
	);
}


/**
 * @return string : empty string or get-parameter-string which is needed for Slim redirects 
 */
function getNoSurSuffix($prefixQuestionmark = TRUE) {
	return (\Slim\Slim::getInstance()->request->get("nosurrounding") == 1)
		? (($prefixQuestionmark)? "?":"") . "nosurrounding=1"
		: "";
}

function notifyJson($message, $type="info") {
	$out = new stdClass();
	$out->notify = 1;
	$out->message = $message;
	$out->type = $type;
	deliverJson($out);
}

function deliverJson($data) {
	$newResponse = \Slim\Slim::getInstance()->response();
	$newResponse->body(json_encode($data));
	$newResponse->headers->set('Content-Type', 'application/json');
	return $newResponse;
}

{'fraction_non_alphanumeric': 0.22153846153846155, 'fraction_numerical': 0.008205128205128205, 'mean_word_length': 4.504838709677419, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 25, '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': '7299652', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2412, 'n_words': 535}