Changeset 880 for trunk/includes/dbc.php


Ignore:
Timestamp:
Apr 7, 2020, 10:15:48 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/dbc.php

    r815 r880  
    3535
    3636    $this->ColumnFormat = $ColumnFormat;
    37     if($this->ReadUint() != DBC_SIGNATURE) die(NOT_DBC_FILE);
     37    if ($this->ReadUint() != DBC_SIGNATURE) die(NOT_DBC_FILE);
    3838
    3939    $this->RecordCount = $this->ReadUint();
     
    4343
    4444    $this->GenerateOffsetTable();
    45     if($this->EndOffset != $this->RecordSize)
     45    if ($this->EndOffset != $this->RecordSize)
    4646    die(RECORD_SIZE_NOT_MATCH.$this->EndOffset.' <> '.$this->RecordSize);
    4747  }
     
    7171  {
    7272    // Preallocate array
    73     if($this->FieldCount > 0) $this->Offsets = array_fill(0, $this->FieldCount, 0);
     73    if ($this->FieldCount > 0) $this->Offsets = array_fill(0, $this->FieldCount, 0);
    7474      else $this->Offsets = array();
    7575
    7676    $Offset = 0;
    7777    $I = 0;
    78     while($I < $this->FieldCount)
     78    while ($I < $this->FieldCount)
    7979    {
    8080      $this->Offsets[$I] = $Offset;
    81       if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
     81      if (array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
    8282        else $Format = FORMAT_UINT32;
    83       switch($Format)
     83      switch ($Format)
    8484      {
    8585        case FORMAT_BYTE:
     
    100100  private function CellPos($Row, $Column)
    101101  {
    102     return($this->HeaderSize + $Row * $this->RecordSize + $this->Offsets[$Column]);
     102    return $this->HeaderSize + $Row * $this->RecordSize + $this->Offsets[$Column];
    103103  }
    104104
     
    106106  {
    107107    $this->SetPosition($this->CellPos($Row, $Column));
    108     return($this->ReadByte());
     108    return $this->ReadByte();
    109109  }
    110110
     
    112112  {
    113113    $this->SetPosition($this->CellPos($Row, $Column));
    114     return($this->ReadUint());
     114    return $this->ReadUint();
    115115  }
    116116
     
    118118  {
    119119    $this->SetPosition($this->CellPos($Row, $Column));
    120     return($this->ReadInt());
     120    return $this->ReadInt();
    121121  }
    122122
     
    124124  {
    125125    $this->SetPosition($this->CellPos($Row, $Column));
    126     return($this->ReadFloat());
     126    return $this->ReadFloat();
    127127  }
    128128
     
    156156
    157157    $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset;
    158     if($Position >= $this->GetSize()) return('');
     158    if ($Position >= $this->GetSize()) return '';
    159159    $this->SetPosition($Position);
    160160
    161161    $String = '';
    162     while(($Char = $this->ReadChar()) != "\0")
     162    while (($Char = $this->ReadChar()) != "\0")
    163163    {
    164164      $String .= $Char;
    165165    }
    166     return($String);
     166    return $String;
    167167  }
    168168
    169169  public function SetString($Row, $Column, $Value)
    170170  {
    171     if(in_array($Value, $this->StringList))
     171    if (in_array($Value, $this->StringList))
    172172    {
    173173      $this->SetUint($Row, $Column, $this->StringListOffset[array_search($Value, $this->StringList)]);
     
    192192    $this->SetPosition($this->HeaderSize + $this->RecordCount * $this->RecordSize);
    193193    $this->WriteByte(0);
    194     foreach($this->StringList as $Index => $Item)
     194    foreach ($this->StringList as $Index => $Item)
    195195    {
    196196      $this->WriteString($Item."\0");
     
    206206
    207207    // Preallocate array
    208     if($this->FieldCount > 0) $Line = array_fill(0, $this->FieldCount, 0);
     208    if ($this->FieldCount > 0) $Line = array_fill(0, $this->FieldCount, 0);
    209209      else $Line = array();
    210     for($I = 0; $I < $this->FieldCount; $I++)
    211     {
    212       if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
     210    for ($I = 0; $I < $this->FieldCount; $I++)
     211    {
     212      if (array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
    213213        else $Format = FORMAT_UINT32;
    214214      $Record->SetPosition($this->Offsets[$I]);
    215       switch($Format)
     215      switch ($Format)
    216216      {
    217217        case FORMAT_BYTE:
     
    231231
    232232          $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset;
    233           if($Position >= $this->GetSize()) $String = '';
     233          if ($Position >= $this->GetSize()) $String = '';
    234234          else
    235235          {
    236236            $this->SetPosition($Position);
    237237            $String = '';
    238             while(($Char = $this->ReadChar()) != "\0")
     238            while (($Char = $this->ReadChar()) != "\0")
    239239              $String .= $Char;
    240240          }
     
    245245      }
    246246    }
    247     return($Line);
     247    return $Line;
    248248  }
    249249
     
    253253    $Record = new MemoryStream();
    254254
    255     for($I = 0; $I < $this->FieldCount; $I++)
    256     {
    257       if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
     255    for ($I = 0; $I < $this->FieldCount; $I++)
     256    {
     257      if (array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
    258258        else $Format = FORMAT_UINT32;
    259259      $Record->SetPosition($this->Offsets[$I]);
    260       switch($Format)
     260      switch ($Format)
    261261      {
    262262        case FORMAT_BYTE:
     
    273273          break;
    274274        case FORMAT_STRING:
    275           if(in_array($Line[$I], $this->StringList))
     275          if (in_array($Line[$I], $this->StringList))
    276276          {
    277277            $Record->WriteUint($this->StringListOffset[array_search($Line[$I], $this->StringList)]);
     
    291291    $this->SetPosition($this->CellPos($Row, 0));
    292292    $this->WriteBlock($Record->Data, $this->RecordSize);
    293     return($Line);
     293    return $Line;
    294294  }
    295295
    296296  public function GetRecordCount()
    297297  {
    298     return($this->RecordCount);
     298    return $this->RecordCount;
    299299  }
    300300
     
    306306  public function GetFieldCount()
    307307  {
    308     return($this->FieldCount);
     308    return $this->FieldCount;
    309309  }
    310310
Note: See TracChangeset for help on using the changeset viewer.