summaryrefslogtreecommitdiff
path: root/libs/plugins
diff options
context:
space:
mode:
authorUwe.Tews@googlemail.com <Uwe.Tews@googlemail.com>2014-08-02 15:24:28 +0000
committerUwe.Tews@googlemail.com <Uwe.Tews@googlemail.com>2014-08-02 15:24:28 +0000
commit9307f0cfcb419196eb6f55323b1b203b8232151e (patch)
tree01a2869030e26cca319320941de3a432b59c9a29 /libs/plugins
parent9b06625c74ceedf1faf4e77a014c6a67c3cb2c28 (diff)
downloadsmarty-9307f0cfcb419196eb6f55323b1b203b8232151e.tar.gz
smarty-9307f0cfcb419196eb6f55323b1b203b8232151e.tar.bz2
smarty-9307f0cfcb419196eb6f55323b1b203b8232151e.zip
- bugfix modifier wordwrap did output break string wrong if first word was exceeding lenght with cut = true (topic 25193)
Diffstat (limited to 'libs/plugins')
-rw-r--r--libs/plugins/shared.mb_wordwrap.php30
1 files changed, 10 insertions, 20 deletions
diff --git a/libs/plugins/shared.mb_wordwrap.php b/libs/plugins/shared.mb_wordwrap.php
index 09f14b9e..31f4acf0 100644
--- a/libs/plugins/shared.mb_wordwrap.php
+++ b/libs/plugins/shared.mb_wordwrap.php
@@ -28,20 +28,14 @@ if (!function_exists('smarty_mb_wordwrap')) {
$length = 0;
$t = '';
$_previous = false;
+ $_space = false;
foreach ($tokens as $_token) {
$token_length = mb_strlen($_token, Smarty::$_CHARSET);
$_tokens = array($_token);
if ($token_length > $width) {
- // remove last space
- $t = mb_substr($t, 0, - 1, Smarty::$_CHARSET);
- $_previous = false;
- $length = 0;
-
- if ($cut) {
+ if ($cut) {
$_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
- // broken words go on a new line
- $t .= $break;
}
}
@@ -52,27 +46,23 @@ if (!function_exists('smarty_mb_wordwrap')) {
if ($length > $width) {
// remove space before inserted break
- if ($_previous && $token_length < $width) {
+ if ($_previous) {
$t = mb_substr($t, 0, - 1, Smarty::$_CHARSET);
}
- // add the break before the token
- $t .= $break;
- $length = $token_length;
-
- // skip space after inserting a break
- if ($_space) {
- $length = 0;
- continue;
+ 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;
- } else {
- // remember if we had a space or not
- $_previous = $_space;
}
+ $_previous = $_space;
// add the token
$t .= $token;
}