12 namespace Symfony\Component\Console\Helper;
52 public static function strlen($string)
54 if (!function_exists(
'mb_strwidth')) {
58 if (
false === $encoding = mb_detect_encoding($string)) {
62 return mb_strwidth($string, $encoding);
67 static $timeFormats = array(
72 array(3600,
'mins', 60),
74 array(86400,
'hrs', 3600),
75 array(129600,
'1 day'),
76 array(604800,
'days', 86400),
79 foreach ($timeFormats as $format) {
80 if ($secs >= $format[0]) {
84 if (2 == count($format)) {
88 return ceil($secs / $format[2]).
' '.$format[1];
94 if ($memory >= 1024 * 1024 * 1024) {
95 return sprintf(
'%.1f GiB', $memory / 1024 / 1024 / 1024);
98 if ($memory >= 1024 * 1024) {
99 return sprintf(
'%.1f MiB', $memory / 1024 / 1024);
102 if ($memory >= 1024) {
103 return sprintf(
'%d KiB', $memory / 1024);
106 return sprintf(
'%d B', $memory);
114 $string = $formatter->
format($string);
116 $string = preg_replace(
"/\033\[[^m]*m/",
'', $string);
119 return self::strlen($string);