Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / console / Helper / FormatterHelper.php
index ac736f982e5c16d02b3c7fda68e051cfb458491b..6a48a77f269016aa440a9aacffefdfd9a271ff31 100644 (file)
@@ -72,6 +72,30 @@ class FormatterHelper extends Helper
         return implode("\n", $messages);
     }
 
+    /**
+     * Truncates a message to the given length.
+     *
+     * @param string $message
+     * @param int    $length
+     * @param string $suffix
+     *
+     * @return string
+     */
+    public function truncate($message, $length, $suffix = '...')
+    {
+        $computedLength = $length - $this->strlen($suffix);
+
+        if ($computedLength > $this->strlen($message)) {
+            return $message;
+        }
+
+        if (false === $encoding = mb_detect_encoding($message, null, true)) {
+            return substr($message, 0, $length).$suffix;
+        }
+
+        return mb_substr($message, 0, $length, $encoding).$suffix;
+    }
+
     /**
      * {@inheritdoc}
      */