mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
- bugfix modifier wordwrap did output break string wrong if first word was exceeding lenght with cut = true (topic 25193)
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
===== 3.1.20-dev ===== (xx.xx.2014)
|
===== 3.1.20-dev ===== (xx.xx.2014)
|
||||||
|
02.08.2014
|
||||||
|
- bugfix modifier wordwrap did output break string wrong if first word was exceeding lenght with cut = true (topic 25193)
|
||||||
|
|
||||||
24.07.2014
|
24.07.2014
|
||||||
- bugfix cache clear when cache folder does not exist
|
- bugfix cache clear when cache folder does not exist
|
||||||
|
|
||||||
|
@@ -28,20 +28,14 @@ if (!function_exists('smarty_mb_wordwrap')) {
|
|||||||
$length = 0;
|
$length = 0;
|
||||||
$t = '';
|
$t = '';
|
||||||
$_previous = false;
|
$_previous = false;
|
||||||
|
$_space = false;
|
||||||
|
|
||||||
foreach ($tokens as $_token) {
|
foreach ($tokens as $_token) {
|
||||||
$token_length = mb_strlen($_token, Smarty::$_CHARSET);
|
$token_length = mb_strlen($_token, Smarty::$_CHARSET);
|
||||||
$_tokens = array($_token);
|
$_tokens = array($_token);
|
||||||
if ($token_length > $width) {
|
if ($token_length > $width) {
|
||||||
// remove last space
|
if ($cut) {
|
||||||
$t = mb_substr($t, 0, - 1, Smarty::$_CHARSET);
|
|
||||||
$_previous = false;
|
|
||||||
$length = 0;
|
|
||||||
|
|
||||||
if ($cut) {
|
|
||||||
$_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
|
$_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) {
|
if ($length > $width) {
|
||||||
// remove space before inserted break
|
// remove space before inserted break
|
||||||
if ($_previous && $token_length < $width) {
|
if ($_previous) {
|
||||||
$t = mb_substr($t, 0, - 1, Smarty::$_CHARSET);
|
$t = mb_substr($t, 0, - 1, Smarty::$_CHARSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the break before the token
|
if (!$_space) {
|
||||||
$t .= $break;
|
// add the break before the token
|
||||||
$length = $token_length;
|
if (!empty($t)) {
|
||||||
|
$t .= $break;
|
||||||
// skip space after inserting a break
|
}
|
||||||
if ($_space) {
|
$length = $token_length;
|
||||||
$length = 0;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
} elseif ($token == "\n") {
|
} elseif ($token == "\n") {
|
||||||
// hard break must reset counters
|
// hard break must reset counters
|
||||||
$_previous = 0;
|
$_previous = 0;
|
||||||
$length = 0;
|
$length = 0;
|
||||||
} else {
|
|
||||||
// remember if we had a space or not
|
|
||||||
$_previous = $_space;
|
|
||||||
}
|
}
|
||||||
|
$_previous = $_space;
|
||||||
// add the token
|
// add the token
|
||||||
$t .= $token;
|
$t .= $token;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user