<commit_before><?php

namespace mako
{
	/**
	* Collection of string manipulation methods.
	*
	* @author     <NAME>
	* @copyright  (c) 2008-2012 <NAME>
	* @license    http://www.makoframework.com/license
	*/

	class String
	{
		//---------------------------------------------
		// Class variables
		//---------------------------------------------

		/**
		* Alphanumeric characters.
		*/

		const ALNUM = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

		/**
		* Alphabetic characters.
		*/

		const ALPHA = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

		/**
		* Hexadecimal characters.
		*/
		
		const HEXDEC = '0123456789abcdef';

		/**
		* Numeric characters.
		*/

		const NUMERIC = '0123456789';

		/**
		* ASCII symbols.
		*/

		const SYMBOLS = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';

		//---------------------------------------------
		// Class constructor, destructor etc ...
		//---------------------------------------------

		/**
		* Protected constructor since this is a static class.
		*
		* @access  protected
		*/

		protected function __construct()
		{
			// Nothing here
		}

		//---------------------------------------------
		// Class methods
		//---------------------------------------------

		/**
		* Alias of htmlspecialchars but it also works on arrays.
		*
		* @access  public
		* @param   mixed    String or array to encode
		* @param   boolean  (optional) True to enable double encoding of entities and false to disable
		* @return  mixed
		*/

		public static function specialCharsEncode($input, $doubleEncode = true)
		{
			if(is_array($input))
			{
				foreach($input as $k => $v)
				{
					$input[$k] = static::specialCharsEncode($v, $doubleEncode);
				}
			}
			else
			{
				$input = htmlspecialchars($input, ENT_COMPAT, mb_internal_encoding(), $doubleEncode);
			}

			return $input;
		}

		/**
		* Alias of htmlspecialchars_decode but it also works on arrays.
		*
		* @access  public
		* @param   mixed  String or array to decode
		* @return  mixed
		*/

		public static function specialCharsDecode($input)
		{
			if(is_array($input))
			{
				foreach($input as $k => $v)
				{
					$input[$k] = static::specialCharsDecode($v);
				}
			}
			else
			{
				$input = htmlspecialchars_decode($input, ENT_COMPAT);
			}

			return $input;
		}

		/**
		* Replaces newline with <br />.
		*
		* @access  public
		* @param   string  The input string
		* @return  string
		*/

		public static function nl2Br($string)
		{
			return str_replace(array("\r\n", "\n\r", "\n", "\r"), '<br />', $string);
		}

		/**
		* Replaces <br> and <br /> with newline.
		*
		* @access  public
		* @param   string  The input string
		* @return  string
		*/

		public static function br2Nl($string)
		{
			return str_replace(array('<br>', '<br />'), "\n", $string);
		}

		/**
		* Converts & to &amp;.
		*
		* @access  public
		* @param   string  The input string
		* @return  string
		*/

		public static function ampEncode($string)
		{
			return str_replace('&', '&amp;', $string);
		}

		/**
		* Converts &amp; to &.
		*
		* @access  public
		* @param   string  The input string
		* @return  string
		*/

		public static function ampDecode($string)
		{
			return str_replace('&amp;', '&', $string);
		}

		/**
		* Limits the number of characters in a string.
		*
		* @access  public
		* @param   string  The input string
		* @param   int     (optional) Number of characters to allow
		* @param   string  (optional) Sufix to add if number of characters is reduced
		*/

		public static function limitCharacters($string, $length, $sufix = '...')
		{
			return (mb_strlen($string) > $length) ? trim(mb_substr($string, 0, $length)) . $sufix : $string;
		}

		/**
		* Limits the number of words in a string.
		*
		* @access  public
		* @param   string  The input string
		* @param   int     (optional) Number of words to allow
		* @param   string  (optional) Sufix to add if number of words is reduced
		*/
<commit_msg>Renamed String::limitCharacters to String::truncate<commit_after><?php

namespace mako
{
	/**
	* Collection of string manipulation methods.
	*
	* @author     <NAME>
	* @copyright  (c) 2008-2012 <NAME>
	* @license    http://www.makoframework.com/license
	*/

	class String
	{
		//---------------------------------------------
		// Class variables
		//---------------------------------------------

		/**
		* Alphanumeric characters.
		*/

		const ALNUM = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

		/**
		* Alphabetic characters.
		*/

		const ALPHA = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

		/**
		* Hexadecimal characters.
		*/
		
		const HEXDEC = '0123456789abcdef';

		/**
		* Numeric characters.
		*/

		const NUMERIC = '0123456789';

		/**
		* ASCII symbols.
		*/

		const SYMBOLS = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';

		//---------------------------------------------
		// Class constructor, destructor etc ...
		//---------------------------------------------

		/**
		* Protected constructor since this is a static class.
		*
		* @access  protected
		*/

		protected function __construct()
		{
			// Nothing here
		}

		//---------------------------------------------
		// Class methods
		//---------------------------------------------

		/**
		* Alias of htmlspecialchars but it also works on arrays.
		*
		* @access  public
		* @param   mixed    String or array to encode
		* @param   boolean  (optional) True to enable double encoding of entities and false to disable
		* @return  mixed
		*/

		public static function specialCharsEncode($input, $doubleEncode = true)
		{
			if(is_array($input))
			{
				foreach($input as $k => $v)
				{
					$input[$k] = static::specialCharsEncode($v, $doubleEncode);
				}
			}
			else
			{
				$input = htmlspecialchars($input, ENT_COMPAT, mb_internal_encoding(), $doubleEncode);
			}

			return $input;
		}

		/**
		* Alias of htmlspecialchars_decode but it also works on arrays.
		*
		* @access  public
		* @param   mixed  String or array to decode
		* @return  mixed
		*/

		public static function specialCharsDecode($input)
		{
			if(is_array($input))
			{
				foreach($input as $k => $v)
				{
					$input[$k] = static::specialCharsDecode($v);
				}
			}
			else
			{
				$input = htmlspecialchars_decode($input, ENT_COMPAT);
			}

			return $input;
		}

		/**
		* Replaces newline with <br />.
		*
		* @access  public
		* @param   string  The input string
		* @return  string
		*/

		public static function nl2Br($string)
		{
			return str_replace(array("\r\n", "\n\r", "\n", "\r"), '<br />', $string);
		}

		/**
		* Replaces <br> and <br /> with newline.
		*
		* @access  public
		* @param   string  The input string
		* @return  string
		*/

		public static function br2Nl($string)
		{
			return str_replace(array('<br>', '<br />'), "\n", $string);
		}

		/**
		* Converts & to &amp;.
		*
		* @access  public
		* @param   string  The input string
		* @return  string
		*/

		public static function ampEncode($string)
		{
			return str_replace('&', '&amp;', $string);
		}

		/**
		* Converts &amp; to &.
		*
		* @access  public
		* @param   string  The input string
		* @return  string
		*/

		public static function ampDecode($string)
		{
			return str_replace('&amp;', '&', $string);
		}

		/**
		* Truncates a string to the desired length.
		*
		* @access  public
		* @param   string  The input string
		* @param   int     (optional) Number of characters to allow
		* @param   string  (optional) Sufix to add if number of characters is reduced
		*/

		public static function truncate($string, $length, $sufix = '...')
		{
			return (mb_strlen($string) > $length) ? trim(mb_substr($string, 0, $length)) . $sufix : $string;
		}

		/**
		* Limits the number of words in a string.
		*
		* @access  public
		* @param   string  The input string
		* @param   int     (optional) Number of words to allow
		* @param   string  (optional) Sufix to add if number of words is reduced
		*/

{'fraction_non_alphanumeric': 0.20236895161290322, 'fraction_numerical': 0.01033266129032258, 'mean_word_length': 2.0562187139006545, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5868373', 'n_tokens_mistral': 3125, 'n_tokens_neox': 2576, 'n_words': 660}