mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
Use ltrim instead of a manual loop to remove trailing lines in ini writer
refs #8706
This commit is contained in:
parent
4c6a2b4f06
commit
6661d49bd2
@ -314,7 +314,7 @@ class IniEditor
|
|||||||
public function getText()
|
public function getText()
|
||||||
{
|
{
|
||||||
$this->cleanUpWhitespaces();
|
$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()
|
private function cleanUpWhitespaces()
|
||||||
{
|
{
|
||||||
$i = count($this->text) - 1;
|
$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--) {
|
for (; $i > 0; $i--) {
|
||||||
$line = $this->text[$i];
|
$line = $this->text[$i];
|
||||||
if ($this->isSectionDeclaration($line) && $i > 0) {
|
if ($this->isSectionDeclaration($line) && $i > 0) {
|
||||||
@ -357,8 +351,6 @@ class IniEditor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// always end file with a linebreak
|
|
||||||
$this->insertAtLine(count($this->text) + 1, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user