|
|
@@ -306,7 +306,7 @@ class Text
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Unicode aware version of wordwrap.
|
|
|
+ * Unicode and newline aware version of wordwrap.
|
|
|
*
|
|
|
* @param string $text The text to format.
|
|
|
* @param int $width The width to wrap to. Defaults to 72.
|
|
|
@@ -316,6 +316,24 @@ class Text
|
|
|
*/
|
|
|
public static function wordWrap($text, $width = 72, $break = "\n", $cut = false)
|
|
|
{
|
|
|
+ $paragraphs = explode($break, $text);
|
|
|
+ foreach ($paragraphs as &$paragraph) {
|
|
|
+ $paragraph = String::_wordWrap($paragraph, $width, $break, $cut);
|
|
|
+ }
|
|
|
+ return implode($break, $paragraphs);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Unicode aware version of wordwrap as helper method.
|
|
|
+ *
|
|
|
+ * @param string $text The text to format.
|
|
|
+ * @param int $width The width to wrap to. Defaults to 72.
|
|
|
+ * @param string $break The line is broken using the optional break parameter. Defaults to '\n'.
|
|
|
+ * @param bool $cut If the cut is set to true, the string is always wrapped at the specified width.
|
|
|
+ * @return string Formatted text.
|
|
|
+ */
|
|
|
+ protected static function _wordWrap($text, $width = 72, $break = "\n", $cut = false)
|
|
|
+ {
|
|
|
if ($cut) {
|
|
|
$parts = [];
|
|
|
while (mb_strlen($text) > 0) {
|