Skip to content

Commit

Permalink
Output buffer 'matter' simplification.
Browse files Browse the repository at this point in the history
  • Loading branch information
André L F S Bacci committed Oct 22, 2024
1 parent bdd9ffb commit 9a070ee
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions scripts/translation/lib/OutputIgnoreBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OutputIgnoreBuffer

private string $filename = "";
private string $header = "";
private array $texts = array();
private array $matter = array();
private array $footer = array();

private OutputIgnoreArgv $args;
Expand All @@ -39,7 +39,7 @@ function __construct( OutputIgnoreArgv $args , string $header , string $filename

function add( string $text )
{
$this->texts[] = $text;
$this->matter[] = $text;
}

function addDiff( string $text , int $sourceCount , int $targetCount )
Expand Down Expand Up @@ -68,18 +68,15 @@ function addFooter( string $text )

function addLine()
{
if ( count( $this->texts ) > 0 && end( $this->texts ) != "\n" )
if ( count( $this->matter ) > 0 && end( $this->matter ) != "\n" )
$this->add( "\n" );
}

function print()
{
if ( count( $this->texts ) == 0 )
if ( count( $this->matter ) == 0 )
return;

$this->addLine( "\n" );
if ( count ( $this->texts ) > 0 )
$this->printCount++;
$this->printCount++;

// footer

Expand All @@ -92,11 +89,11 @@ function print()
// --add-ignore

if ( in_array( $markfull , $marks ) )
$this->texts = array();
$this->matter = array();
else
$this->args->pushAddIgnore( $this , $markfull );

// remove duplicates
// Avoid dupliocates on output

while ( in_array( $markfull , $marks ) )
{
Expand All @@ -112,29 +109,29 @@ function print()
$this->args->pushDelIgnore( $this , $mark );
}

$this->addLine( "\n" );

if ( count( $this->texts ) == 0 )
if ( count( $this->matter ) == 0 && count( $this->footer ) == 0 )
return;

print $this->header;

foreach( $this->texts as $text )
foreach( $this->matter as $text )
print $text;

if ( count( $this->matter ) )
print "\n";

foreach( $this->footer as $text )
print $text;

if ( count( $this->footer ) )
{
foreach( $this->footer as $text )
print $text;
print "\n";
}
}

private function hash( bool $withContents ) : string
{
$text = $this->header . $this->args->options;
if ( $withContents )
$text .= implode( "" , $this->texts );
$text .= implode( "" , $this->matter );
$text = str_replace( " " , "" , $text );
$text = str_replace( "\n" , "" , $text );
$text = str_replace( "\r" , "" , $text );
Expand Down

0 comments on commit 9a070ee

Please sign in to comment.