convert : Add folding

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5729 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-11-15 21:05:08 +00:00
parent e917ef6653
commit 78922b2521

View File

@@ -21,6 +21,7 @@ class convert
*/
public static function convertDate ($inputDate, $inputFormat, $outputFormat,
$exception = true)
// {{{
{
if (! is_string ($inputDate))
throw new \Exception ("The date to convert is not a string", 500);
@@ -46,12 +47,14 @@ class convert
}
return $date->format ($outputFormat);
}
// }}}
/** Convert the first char to capital and the rest of the sentence in
* lowercase (like ucfirst, but UTF8 compliant)
* @param string $str The string to convert
*/
public static function ucfirst ($str)
// {{{
{
if (! function_exists ("mb_strtoupper"))
throw new \Exception ("PHP don't have the MB Support. Please add it !",
@@ -59,6 +62,7 @@ class convert
$a = mb_strtoupper (mb_substr ($str, 0, 1, 'UTF-8'), 'UTF-8');
return $a . mb_substr ($str, 1, null, 'UTF-8');
}
// }}}
/** Convert the first char of each word of a sentence to capital. The word
* delimiter can be provided.
@@ -70,6 +74,7 @@ class convert
* @return string
*/
public static function ucwords ($str, $delimiters = " \t\r\n\f\v")
// {{{
{
if (! function_exists ("mb_strtolower"))
throw new \Exception ("PHP don't have the MB Support. Please add it !",
@@ -83,6 +88,7 @@ class convert
}
return $res;
}
// }}}
/** Convert the provided float to human readable format
* Example : 1440000 => 1.44MB
@@ -94,6 +100,7 @@ class convert
*/
public static function humanSize ($value, $decimals = 2, $power = 1000,
$unit = "B")
// {{{
{
if (! is_integer ($value) && ! is_float ($value))
throw new \Exception ("convert::humanSize value not numerical : ".
@@ -138,4 +145,5 @@ class convert
return sprintf ("%.${decimals}f", $display).$size[$factor].$unit;
}
// }}}
}