Improve _convert_line() performance

pull/191/head
Aleksander Machniak 11 years ago
parent b5bb6479bc
commit d9d276ea70

@ -259,14 +259,20 @@ class rcube_text2html
// replace spaces with non-breaking spaces // replace spaces with non-breaking spaces
if ($is_flowed) { if ($is_flowed) {
$text = preg_replace_callback('/(^|[^ ])( +)/', function($matches) { $pos = 0;
if (!strlen($matches[2])) { $diff = 0;
return str_repeat($nbsp, strlen($matches[2])); $len = strlen($nbsp);
} $copy = $text;
else {
return $matches[1] . ' ' . str_repeat($nbsp, strlen($matches[2])-1); while (($pos = strpos($text, ' ', $pos)) !== false) {
} if ($pos == 0 || $text[$pos-1] == ' ') {
}, $text); $copy = substr_replace($copy, $nbsp, $pos + $diff, 1);
$diff += $len - 1;
}
$pos++;
}
$text = $copy;
} }
else { else {
$text = str_replace(' ', $nbsp, $text); $text = str_replace(' ', $nbsp, $text);

Loading…
Cancel
Save