<commit_before><?php

	function hex_dump( $value )
	{
		
		$to_hex = function( $number ){
			$hex = strtoupper( dechex( $number ) );
			//if we don't check if the number is 0, it won't fill the whole space
			return ( $number === 0 || strlen( $hex ) & 1 ? '0' : '' ) . $hex;
		};
		$lines = array();
		$start_time = microtime(true);
		
		switch( gettype( $value ) )
		{
			case 'string':
				
				foreach( str_split( $value, 16 ) as $k => $line )
				{
					$lines[$k] = array();
					
					for( $i = 0, $l = strlen($line); $i<$l; $i++)
					{
						$lines[$k][$i] = $to_hex( ord( $line[$i] ) );
					}
				}
				
				break;
				
			case 'double':
			case 'integer':
			case 'boolean':
			case 'NULL':
				$lines[0] = str_split( $to_hex( $value ), 2 );
				break;
				
			case 'array':
				foreach( array_chunk( $value, 16, false ) as $k => $chunk )
				{
					foreach( $chunk as $k => $item )
					{
						switch( gettype( $item ) )
						{
							case 'double':
							case 'integer':
							case 'boolean':
							case 'NULL':
								if( $item > 255 )
								{
									trigger_error( 'hex_dump() numbers in a byte array cannot be higher than 255 on index ' . $k, E_USER_WARNING );
								}
								//we need to fix the number, if it isn't a single byte
								$chunk[$k] = $to_hex( $item & 255 );
								break;
							case 'string':
								if( strlen( $item ) > 1 )
								{
									trigger_error( 'hex_dump() strings in a byte array cannot have more than 1 character on index ' . $k, E_USER_WARNING );
								}
								//disregard the remaining of the string, since only the 1st char matters
								$chunk[$k] = $to_hex( ord( $item[0] ) );
								break;
							default:
								$chunk[$k] = '--';
								trigger_error( 'hex_dump() invalid value on index ' . $k, E_USER_WARNING );
						}
					}	
					$lines[] = $chunk;
				}
				break;
				
			default:
				trigger_error( 'Invalid value type passed', E_USER_WARNING );
				return false;
		}
		
		$line_count = count( $lines );
		
		$num_length = strlen( dechex( $lines ) ) + 1;
		$num_length = $num_length + ( $num_length % 2 );
		
		$header = str_repeat( ' ',  $num_length ) . ' |';
		for( $number = 0; $number < 16; $number++ )
		{
			$header .= '0' . dechex( $number ) . '|';<commit_msg>Fixed line number not being padded<commit_after><?php

	function hex_dump( $value )
	{
		
		$to_hex = function( $number ){
			$hex = strtoupper( dechex( $number ) );
			//if we don't check if the number is 0, it won't fill the whole space
			return ( $number === 0 || strlen( $hex ) & 1 ? '0' : '' ) . $hex;
		};
		$lines = array();
		$start_time = microtime(true);
		
		switch( gettype( $value ) )
		{
			case 'string':
				
				foreach( str_split( $value, 16 ) as $k => $line )
				{
					$lines[$k] = array();
					
					for( $i = 0, $l = strlen($line); $i<$l; $i++)
					{
						$lines[$k][$i] = $to_hex( ord( $line[$i] ) );
					}
				}
				
				break;
				
			case 'double':
			case 'integer':
			case 'boolean':
			case 'NULL':
				$lines[0] = str_split( $to_hex( $value ), 2 );
				break;
				
			case 'array':
				foreach( array_chunk( $value, 16, false ) as $k => $chunk )
				{
					foreach( $chunk as $k => $item )
					{
						switch( gettype( $item ) )
						{
							case 'double':
							case 'integer':
							case 'boolean':
							case 'NULL':
								if( $item > 255 )
								{
									trigger_error( 'hex_dump() numbers in a byte array cannot be higher than 255 on index ' . $k, E_USER_WARNING );
								}
								//we need to fix the number, if it isn't a single byte
								$chunk[$k] = $to_hex( $item & 255 );
								break;
							case 'string':
								if( strlen( $item ) > 1 )
								{
									trigger_error( 'hex_dump() strings in a byte array cannot have more than 1 character on index ' . $k, E_USER_WARNING );
								}
								//disregard the remaining of the string, since only the 1st char matters
								$chunk[$k] = $to_hex( ord( $item[0] ) );
								break;
							default:
								$chunk[$k] = '--';
								trigger_error( 'hex_dump() invalid value on index ' . $k, E_USER_WARNING );
						}
					}	
					$lines[] = $chunk;
				}
				break;
				
			default:
				trigger_error( 'Invalid value type passed', E_USER_WARNING );
				return false;
		}
		
		$line_count = count( $lines );
		
		$num_length = strlen( dechex( $line_count ) ) + 1;
		$num_length = $num_length + ( $num_length % 2 );
		
		$header = str_repeat( ' ',  $num_length ) . ' |';
		for( $number = 0; $number < 16; $number++ )
		{
			$header .= '0' . dechex( $number ) . '|';
{'fraction_non_alphanumeric': 0.16248348745046234, 'fraction_numerical': 0.013210039630118891, 'mean_word_length': 2.040829986613119, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '199399', 'n_tokens_mistral': 2253, 'n_tokens_neox': 1562, 'n_words': 463}