private function Application::splitStringByWidth in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/console/Application.php \Symfony\Component\Console\Application::splitStringByWidth()
1 call to Application::splitStringByWidth()
- Application::renderException in vendor/symfony/console/Application.php
- Renders a caught exception.
File
- vendor/symfony/console/Application.php, line 1080
Class
- Application
- An Application is the container for a collection of commands.
Namespace
Symfony\Component\Console
Code
private function splitStringByWidth($string, $width) {
if (!function_exists('mb_strwidth')) {
return str_split($string, $width);
}
if (false === ($encoding = mb_detect_encoding($string))) {
return str_split($string, $width);
}
$utf8String = mb_convert_encoding($string, 'utf8', $encoding);
$lines = array();
$line = '';
foreach (preg_split('//u', $utf8String) as $char) {
if (mb_strwidth($line . $char, 'utf8') <= $width) {
$line .= $char;
continue;
}
$lines[] = str_pad($line, $width);
$line = $char;
}
if ('' !== $line) {
$lines[] = count($lines) ? str_pad($line, $width) : $line;
}
mb_convert_variables($encoding, 'utf8', $lines);
return $lines;
}