diff options
Diffstat (limited to 'vendor/symfony/console/Helper/Helper.php')
-rw-r--r-- | vendor/symfony/console/Helper/Helper.php | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/vendor/symfony/console/Helper/Helper.php b/vendor/symfony/console/Helper/Helper.php index 43f9a169..0954bad6 100644 --- a/vendor/symfony/console/Helper/Helper.php +++ b/vendor/symfony/console/Helper/Helper.php @@ -23,9 +23,7 @@ abstract class Helper implements HelperInterface protected $helperSet = null; /** - * Sets the helper set associated with this helper. - * - * @param HelperSet $helperSet A HelperSet instance + * {@inheritdoc} */ public function setHelperSet(HelperSet $helperSet = null) { @@ -33,9 +31,7 @@ abstract class Helper implements HelperInterface } /** - * Gets the helper set associated with this helper. - * - * @return HelperSet A HelperSet instance + * {@inheritdoc} */ public function getHelperSet() { @@ -58,6 +54,24 @@ abstract class Helper implements HelperInterface return mb_strwidth($string, $encoding); } + /** + * Returns the subset of a string, using mb_substr if it is available. + * + * @param string $string String to subset + * @param int $from Start offset + * @param int|null $length Length to read + * + * @return string The string subset + */ + public static function substr($string, $from, $length = null) + { + if (false === $encoding = mb_detect_encoding($string, null, true)) { + return substr($string, $from, $length); + } + + return mb_substr($string, $from, $length, $encoding); + } + public static function formatTime($secs) { static $timeFormats = array( @@ -106,6 +120,11 @@ abstract class Helper implements HelperInterface public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, $string) { + return self::strlen(self::removeDecoration($formatter, $string)); + } + + public static function removeDecoration(OutputFormatterInterface $formatter, $string) + { $isDecorated = $formatter->isDecorated(); $formatter->setDecorated(false); // remove <...> formatting @@ -114,6 +133,6 @@ abstract class Helper implements HelperInterface $string = preg_replace("/\033\[[^m]*m/", '', $string); $formatter->setDecorated($isDecorated); - return self::strlen($string); + return $string; } } |