<commit_before><?php

final class Language {

	/** @return string */
	public static function MakeHref($lang){
		return Oxygen::MakeHrefPreservingValues(array('lang'=>$lang));
	}

	/** @return string */
	public static function GetDecimalSeparator(){
		$l = Lemma::Pick('DecimalSeparator');
		return $l->HasLang() ? $l->Translate() : self::GetDecimalSeparatorInvariant();
	}
	/** @return string */
	public static function GetThousandsSeparator(){
		$l = Lemma::Pick('ThousandsSeparator');
		return $l->HasLang() ? $l->Translate() : self::GetThousandsSeparatorInvariant();
	}

	/** @return string */
	public static function GetDecimalSeparatorInvariant(){
		return '.';
	}
	/** @return string */
	public static function GetThousandsSeparatorInvariant(){
		return '';
	}


	/** @return string */
	public static function FormatDecimal($value,$number_of_decimals=-1) {
		if (is_int($value) || is_float($value)){
			if ($number_of_decimals < 0) {
				$number_of_decimals = 0;
				$s = sprintf('%F',$value);
				$x = strstr($s,self::GetDecimalSeparatorInvariant());
				if ($x !== false) {
					$s = rtrim($s,'0');
					$x = strstr($s,self::GetDecimalSeparatorInvariant());
					$number_of_decimals = strlen($x) - 1;
				}
				if ($number_of_decimals == 0) $number_of_decimals = 1;
			}
			return number_format($value, $number_of_decimals, self::GetDecimalSeparator(), self::GetThousandsSeparator());
		}
		return '';
	}
	/** @return float|null */
	public static function ParseDecimal($string, $default = null) {
		$string = strval($string);
		$s = preg_replace('/[^1234567890\\'.self::GetDecimalSeparator().']/','',$string);
		$s = str_replace( self::GetDecimalSeparator() , self::GetDecimalSeparatorInvariant() , $s );
		$s_length = strlen($s);
		$d_count = substr_count($s,self::GetDecimalSeparatorInvariant());
		if ($d_count == $s_length || $d_count > 1 || $s_length == 0) return $default;
		return floatval($s);
	}

	/** @return string */
	public static function FormatDecimalInvariant($value,$number_of_decimals=-1) {
		if (is_int($value) || is_float($value)){
			if ($number_of_decimals < 0) {
				$number_of_decimals = 0;
				$s = sprintf('%F',$value);
				$x = strstr($s,self::GetDecimalSeparatorInvariant());
				if ($x !== false) {
					$s = rtrim($s,'0');
					$x = strstr($s,self::GetDecimalSeparatorInvariant());
					$number_of_decimals = strlen($x) - 1;
				}
				if ($number_of_decimals == 0) $number_of_decimals = 1;
			}
			return number_format($value, $number_of_decimals, self::GetDecimalSeparatorInvariant(), self::GetThousandsSeparatorInvariant());
		}
		return '';
	}
	/** @return float|null */
	public static function ParseDecimalInvariant($string, $default = null) {
		$string = strval($string);
		$s = preg_replace('/[^1234567890\\'.self::GetDecimalSeparatorInvariant().']/','',$string);
		$s_length = strlen($s);
		$d_count = substr_count($s,self::GetDecimalSeparatorInvariant());
		if ($d_count == $s_length || $d_count > 1 || $s_length == 0) return $default;
		return floatval($s);
	}





	/** @return string */
	public static function FormatNumber($value,$number_of_decimals=-1) {
		if (is_int($value) || is_float($value)){
			if ($number_of_decimals < 0) {
				$number_of_decimals = 0;
				$s = sprintf('%F',$value);
				$x = strstr($s,self::GetDecimalSeparatorInvariant());
				if ($x !== false) {
					$s = rtrim($s,'0');
					$x = strstr($s,self::GetDecimalSeparatorInvariant());
					$number_of_decimals = strlen($x) - 1;
				}
			}
			return number_format($value, $number_of_decimals, self::GetDecimalSeparator(), self::GetThousandsSeparator());
		}
		return '';
	}


	/** @return float|int|null */
	public static function ParseNumber($string, $default = null) {
		$string = strval($string);
		$s = preg_replace('/[^1234567890\\'.self::GetDecimalSeparator().']/','',$string);
		$s = str_replace( self::GetDecimalSeparator() , self::GetDecimalSeparatorInvariant() , $s );
		$s_length = strlen($s);
		$d_count = substr_count($s,self::GetDecimalSeparatorInvariant());
		if ($d_count == $s_length || $d_count > 1 || $s_length == 0) return $default;
		$x1 = floatval($s);
		$x2 = intval($x1);
		return $x1 == $x2 ? $x2 : $x1;
	}


	/** @return string */
	public static function FormatNumberInvariant($value,$number_of_decimals=-1) {
		if (is_int($value) || is_float($value)){
			if ($number_of_decimals < 0) {
				$number_of_decimals = 0;
				$s = sprintf('%F',$value);
				$x = strstr($s,self::GetDecimalSeparatorInvariant());
				if ($x !== false) {
					$s = rtrim($s,'0');
					$x = strstr($s,self::GetDecimalSeparatorInvariant());
					$number_of_decimals = strlen($x) - 1;
				}
			}
			return number_format($value, $number_of_decimals, self::GetDecimalSeparatorInvariant(), self::GetThousandsSeparatorInvariant());
		}
		return '';
	}

	/** @return float|int|null */
	public static function ParseNumberInvariant($string, $default = null) {
		$string = strval($string);
		$s = preg_replace('/[^1234567890\\'.self::GetDecimalSeparatorInvariant().']/','',$string);
		$s_length = strlen($s);
		$d_count = substr_count($s,self::GetDecimalSeparatorInvariant());
		if ($d_count == $s_length || $d_count > 1 || $s_length == 0) return $default;
		$x1 = floatval($s);
		$x2 = intval($x1);
		return $x1 == $x2 ? $x2 : $x1;
	}



	/** @return string */
	public static function FormatTimeSpan($value,$show_milliseconds = true){
		if (is_int($value))
			$value = new XTimeSpan($value);
//		if ($value instanceof DateInterval)
//			$value = new XTimeSpan($value);
    if ( $value instanceof XTimeSpan ){
    	$d = $value->GetDays();
    	$h = $value->GetHours();
    	$m = $value->GetMinutes();
    	$s = $value->GetSeconds();
	    $ms = $value->GetMilliseconds();<commit_msg>negative decimals bug<commit_after><?php

final class Language {

	/** @return string */
	public static function MakeHref($lang){
		return Oxygen::MakeHrefPreservingValues(array('lang'=>$lang));
	}

	/** @return string */
	public static function GetDecimalSeparator(){
		$l = Lemma::Pick('DecimalSeparator');
		return $l->HasLang() ? $l->Translate() : self::GetDecimalSeparatorInvariant();
	}
	/** @return string */
	public static function GetThousandsSeparator(){
		$l = Lemma::Pick('ThousandsSeparator');
		return $l->HasLang() ? $l->Translate() : self::GetThousandsSeparatorInvariant();
	}

	/** @return string */
	public static function GetDecimalSeparatorInvariant(){
		return '.';
	}
	/** @return string */
	public static function GetThousandsSeparatorInvariant(){
		return '';
	}


	/** @return string */
	public static function FormatDecimal($value,$number_of_decimals=-1) {
		if (is_int($value) || is_float($value)){
			if ($number_of_decimals < 0) {
				$number_of_decimals = 0;
				$s = sprintf('%F',$value);
				$x = strstr($s,self::GetDecimalSeparatorInvariant());
				if ($x !== false) {
					$s = rtrim($s,'0');
					$x = strstr($s,self::GetDecimalSeparatorInvariant());
					$number_of_decimals = strlen($x) - 1;
				}
				if ($number_of_decimals == 0) $number_of_decimals = 1;
			}
			return number_format($value, $number_of_decimals, self::GetDecimalSeparator(), self::GetThousandsSeparator());
		}
		return '';
	}
	/** @return float|null */
	public static function ParseDecimal($string, $default = null) {
		$string = strval($string);
		$s = preg_replace('/[^-1234567890\\'.self::GetDecimalSeparator().']/','',$string);
		$s = str_replace( self::GetDecimalSeparator() , self::GetDecimalSeparatorInvariant() , $s );
		$s_length = strlen($s);
		$d_count = substr_count($s,self::GetDecimalSeparatorInvariant());
		if ($d_count == $s_length || $d_count > 1 || $s_length == 0) return $default;
		return floatval($s);
	}

	/** @return string */
	public static function FormatDecimalInvariant($value,$number_of_decimals=-1) {
		if (is_int($value) || is_float($value)){
			if ($number_of_decimals < 0) {
				$number_of_decimals = 0;
				$s = sprintf('%F',$value);
				$x = strstr($s,self::GetDecimalSeparatorInvariant());
				if ($x !== false) {
					$s = rtrim($s,'0');
					$x = strstr($s,self::GetDecimalSeparatorInvariant());
					$number_of_decimals = strlen($x) - 1;
				}
				if ($number_of_decimals == 0) $number_of_decimals = 1;
			}
			return number_format($value, $number_of_decimals, self::GetDecimalSeparatorInvariant(), self::GetThousandsSeparatorInvariant());
		}
		return '';
	}
	/** @return float|null */
	public static function ParseDecimalInvariant($string, $default = null) {
		$string = strval($string);
		$s = preg_replace('/[^-1234567890\\'.self::GetDecimalSeparatorInvariant().']/','',$string);
		$s_length = strlen($s);
		$d_count = substr_count($s,self::GetDecimalSeparatorInvariant());
		if ($d_count == $s_length || $d_count > 1 || $s_length == 0) return $default;
		return floatval($s);
	}





	/** @return string */
	public static function FormatNumber($value,$number_of_decimals=-1) {
		if (is_int($value) || is_float($value)){
			if ($number_of_decimals < 0) {
				$number_of_decimals = 0;
				$s = sprintf('%F',$value);
				$x = strstr($s,self::GetDecimalSeparatorInvariant());
				if ($x !== false) {
					$s = rtrim($s,'0');
					$x = strstr($s,self::GetDecimalSeparatorInvariant());
					$number_of_decimals = strlen($x) - 1;
				}
			}
			return number_format($value, $number_of_decimals, self::GetDecimalSeparator(), self::GetThousandsSeparator());
		}
		return '';
	}


	/** @return float|int|null */
	public static function ParseNumber($string, $default = null) {
		$string = strval($string);
		$s = preg_replace('/[^-1234567890\\'.self::GetDecimalSeparator().']/','',$string);
		$s = str_replace( self::GetDecimalSeparator() , self::GetDecimalSeparatorInvariant() , $s );
		$s_length = strlen($s);
		$d_count = substr_count($s,self::GetDecimalSeparatorInvariant());
		if ($d_count == $s_length || $d_count > 1 || $s_length == 0) return $default;
		$x1 = floatval($s);
		$x2 = intval($x1);
		return $x1 == $x2 ? $x2 : $x1;
	}


	/** @return string */
	public static function FormatNumberInvariant($value,$number_of_decimals=-1) {
		if (is_int($value) || is_float($value)){
			if ($number_of_decimals < 0) {
				$number_of_decimals = 0;
				$s = sprintf('%F',$value);
				$x = strstr($s,self::GetDecimalSeparatorInvariant());
				if ($x !== false) {
					$s = rtrim($s,'0');
					$x = strstr($s,self::GetDecimalSeparatorInvariant());
					$number_of_decimals = strlen($x) - 1;
				}
			}
			return number_format($value, $number_of_decimals, self::GetDecimalSeparatorInvariant(), self::GetThousandsSeparatorInvariant());
		}
		return '';
	}

	/** @return float|int|null */
	public static function ParseNumberInvariant($string, $default = null) {
		$string = strval($string);
		$s = preg_replace('/[^-1234567890\\'.self::GetDecimalSeparatorInvariant().']/','',$string);
		$s_length = strlen($s);
		$d_count = substr_count($s,self::GetDecimalSeparatorInvariant());
		if ($d_count == $s_length || $d_count > 1 || $s_length == 0) return $default;
		$x1 = floatval($s);
		$x2 = intval($x1);
		return $x1 == $x2 ? $x2 : $x1;
	}



	/** @return string */
	public static function FormatTimeSpan($value,$show_milliseconds = true){
		if (is_int($value))
			$value = new XTimeSpan($value);
//		if ($value instanceof DateInterval)
//			$value = new XTimeSpan($value);
    if ( $value instanceof XTimeSpan ){
    	$d = $value->GetDays();
    	$h = $value->GetHours();
    	$m = $value->GetMinutes();
    	$s = $value->GetSeconds();
	    $ms = $value->GetMilliseconds();
{'fraction_non_alphanumeric': 0.19, 'fraction_numerical': 0.015087719298245613, 'mean_word_length': 4.624568327577701, 'pattern_counts': {'":': 0, '<': 13, '<?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': '7450051', 'n_tokens_mistral': 4455, 'n_tokens_neox': 3937, 'n_words': 723}