From 7085a0c2f7104a56a7e946c43ba0b5736be5f4e7 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 27 Dec 2016 14:47:01 +0100 Subject: * smarty bundled --- lib/smarty3/plugins/shared.mb_wordwrap.php | 75 ++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 lib/smarty3/plugins/shared.mb_wordwrap.php (limited to 'lib/smarty3/plugins/shared.mb_wordwrap.php') diff --git a/lib/smarty3/plugins/shared.mb_wordwrap.php b/lib/smarty3/plugins/shared.mb_wordwrap.php new file mode 100644 index 0000000..21632a1 --- /dev/null +++ b/lib/smarty3/plugins/shared.mb_wordwrap.php @@ -0,0 +1,75 @@ + $width) { + if ($cut) { + $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1, + PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); + } + } + + foreach ($_tokens as $token) { + $_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token); + $token_length = mb_strlen($token, Smarty::$_CHARSET); + $length += $token_length; + + if ($length > $width) { + // remove space before inserted break + if ($_previous) { + $t = mb_substr($t, 0, - 1, Smarty::$_CHARSET); + } + + if (!$_space) { + // add the break before the token + if (!empty($t)) { + $t .= $break; + } + $length = $token_length; + } + } elseif ($token == "\n") { + // hard break must reset counters + $_previous = 0; + $length = 0; + } + $_previous = $_space; + // add the token + $t .= $token; + } + } + + return $t; + } +} -- cgit v1.2.3