From 6661d49bd268fd4fc78e052c82526bc7f01815ac Mon Sep 17 00:00:00 2001 From: Matthias Jentsch <matthias.jentsch@netways.de> Date: Mon, 1 Jun 2015 17:00:43 +0200 Subject: [PATCH] Use ltrim instead of a manual loop to remove trailing lines in ini writer refs #8706 --- library/Icinga/File/Ini/IniEditor.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/library/Icinga/File/Ini/IniEditor.php b/library/Icinga/File/Ini/IniEditor.php index c324808bc..1f8202d9d 100644 --- a/library/Icinga/File/Ini/IniEditor.php +++ b/library/Icinga/File/Ini/IniEditor.php @@ -314,7 +314,7 @@ class IniEditor public function getText() { $this->cleanUpWhitespaces(); - return implode(PHP_EOL, $this->text); + return rtrim(implode(PHP_EOL, $this->text)) . PHP_EOL; } /** @@ -323,12 +323,6 @@ class IniEditor private function cleanUpWhitespaces() { $i = count($this->text) - 1; - - // remove all trailing whitespaces - while ($i > 0 && preg_match('/^\s*$/', $this->text[$i]) === 1) { - $this->deleteLine($i); - $i--; - } for (; $i > 0; $i--) { $line = $this->text[$i]; if ($this->isSectionDeclaration($line) && $i > 0) { @@ -357,8 +351,6 @@ class IniEditor } } } - // always end file with a linebreak - $this->insertAtLine(count($this->text) + 1, ""); } /**