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