<commit_before><?php
namespace wcf\util;
use wcf\system\application\ApplicationHandler;
use wcf\system\request\RouteHandler;
use wcf\system\WCF;

/**
 * Contains string-related functions.
 * 
 * @author	<NAME>, <NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\Util
 */
final class StringUtil {
	const HTML_PATTERN = '~</?[a-z]+[1-6]?
			(?:\s*[a-z\-]+\s*(=\s*(?:
			"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|[^\s>]
			))?)*\s*/?>~ix';
	const HTML_COMMENT_PATTERN = '~<!--(.*?)-->~';
	
	/**
	 * utf8 bytes of the HORIZONTAL ELLIPSIS (U+2026)
	 * @var	string
	 */
	const HELLIP = "\u{2026}";
	
	/**
	 * utf8 bytes of the MINUS SIGN (U+2212)
	 * @var	string
	 */
	const MINUS = "\u{2212}";
	
	/**
	 * Alias to php sha1() function.
	 * 
	 * @param	string		$value
	 * @return	string
	 */
	public static function getHash($value) {
		return sha1($value);
	}
	
	/**
	 * Returns a 40 character hexadecimal string generated using a CSPRNG.
	 * 
	 * @return	string
	 */
	public static function getRandomID() {
		return bin2hex(random_bytes(20));
	}
	
	/**
	 * Creates an UUID.
	 * 
	 * @return	string
	 */
	public static function getUUID() {
		return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
	}
	
	/**
	 * Converts dos to unix newlines.
	 * 
	 * @param	string		$string
	 * @return	string
	 */
	public static function unifyNewlines($string) {
		return preg_replace("%(\r\n)|(\r)%", "\n", $string);
	}
	
	/**
	 * Removes Unicode whitespace characters from the beginning
	 * and ending of the given string.
	 * 
	 * @param	string		$text
	 * @return	string<commit_msg>Implement StringUtil::getUUID() in terms of a CSPRNG<commit_after><?php
namespace wcf\util;
use wcf\system\application\ApplicationHandler;
use wcf\system\request\RouteHandler;
use wcf\system\WCF;

/**
 * Contains string-related functions.
 * 
 * @author	<NAME>, <NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\Util
 */
final class StringUtil {
	const HTML_PATTERN = '~</?[a-z]+[1-6]?
			(?:\s*[a-z\-]+\s*(=\s*(?:
			"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|[^\s>]
			))?)*\s*/?>~ix';
	const HTML_COMMENT_PATTERN = '~<!--(.*?)-->~';
	
	/**
	 * utf8 bytes of the HORIZONTAL ELLIPSIS (U+2026)
	 * @var	string
	 */
	const HELLIP = "\u{2026}";
	
	/**
	 * utf8 bytes of the MINUS SIGN (U+2212)
	 * @var	string
	 */
	const MINUS = "\u{2212}";
	
	/**
	 * Alias to php sha1() function.
	 * 
	 * @param	string		$value
	 * @return	string
	 */
	public static function getHash($value) {
		return sha1($value);
	}
	
	/**
	 * Returns a 40 character hexadecimal string generated using a CSPRNG.
	 * 
	 * @return	string
	 */
	public static function getRandomID() {
		return bin2hex(random_bytes(20));
	}
	
	/**
	 * Creates an UUID.
	 * 
	 * @return	string
	 */
	public static function getUUID() {
		return sprintf(
			'%04x%04x-%04x-%04x-%02x%02x-%04x%04x%04x',
			// time_low
			random_int(0, 0xffff), random_int(0, 0xffff),
			// time_mid
			random_int(0, 0xffff), 
			// time_hi_and_version
			random_int(0, 0x0fff) | 0x4000,
			// clock_seq_hi_and_res
			random_int(0, 0x3f) | 0x80,
			// clock_seq_low
			random_int(0, 0xff),
			// node
			random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xffff)
		);
	}
	
	/**
	 * Converts dos to unix newlines.
	 * 
	 * @param	string		$string
	 * @return	string
	 */
	public static function unifyNewlines($string) {
		return preg_replace("%(\r\n)|(\r)%", "\n", $string);
	}
	
	/**
	 * Removes Unicode whitespace characters from the beginning
	 * and ending of the given string.
	 * 
	 * @param	string		$text
	 * @return	string
{'fraction_non_alphanumeric': 0.19854051333668848, 'fraction_numerical': 0.04730749874182184, 'mean_word_length': 3.1363163371488034, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6609286', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1508, 'n_words': 336}