mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-22 06:26:57 +01:00
String are being trimmed now
And added default values as well
This commit is contained in:
parent
2e5910f384
commit
d6bcf66b4d
19
src/Sws.php
19
src/Sws.php
@ -455,7 +455,7 @@ class Sws extends SwsModel
|
|||||||
|
|
||||||
// Organising club no
|
// Organising club no
|
||||||
$length = 4;
|
$length = 4;
|
||||||
$sws->getTournament()->setOrganiserClubNo(self::ReadData('String', substr($swscontents, $offset, $length)));
|
$sws->getTournament()->setOrganiserClubNo(self::ReadData('String', substr($swscontents, $offset, $length), 0));
|
||||||
$offset += $length;
|
$offset += $length;
|
||||||
|
|
||||||
// Organising club
|
// Organising club
|
||||||
@ -512,13 +512,17 @@ class Sws extends SwsModel
|
|||||||
/**
|
/**
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $data
|
* @param string $data
|
||||||
|
* @param mixed $default
|
||||||
* @return bool|DateTime|int|string
|
* @return bool|DateTime|int|string
|
||||||
*/
|
*/
|
||||||
private static function ReadData(string $type, string $data)
|
private static function ReadData(string $type, string $data, $default = null)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'String':
|
case 'String':
|
||||||
return $data;
|
if (trim($data) == '') {
|
||||||
|
return (is_null($default)) ? '' : $default;
|
||||||
|
}
|
||||||
|
return trim($data);
|
||||||
break;
|
break;
|
||||||
case 'Hex':
|
case 'Hex':
|
||||||
case 'Int':
|
case 'Int':
|
||||||
@ -538,10 +542,19 @@ class Sws extends SwsModel
|
|||||||
$hex = implode($hex);
|
$hex = implode($hex);
|
||||||
$hex = ($hex == "") ? "00" : $hex;
|
$hex = ($hex == "") ? "00" : $hex;
|
||||||
if ($type == 'Hex') {
|
if ($type == 'Hex') {
|
||||||
|
if ($hex == '00') {
|
||||||
|
return (is_null($default)) ? '00' : $default;
|
||||||
|
}
|
||||||
return $hex;
|
return $hex;
|
||||||
} elseif ($type == 'Int') {
|
} elseif ($type == 'Int') {
|
||||||
|
if ($hex == '00') {
|
||||||
|
return (is_null($default)) ? 0 : $default;
|
||||||
|
}
|
||||||
return hexdec($hex);
|
return hexdec($hex);
|
||||||
} elseif ($type == 'Date') {
|
} elseif ($type == 'Date') {
|
||||||
|
if ($hex == '00') {
|
||||||
|
return (is_null($default)) ? self::UIntToTimestamp(0) : $default;
|
||||||
|
}
|
||||||
return self::UIntToTimestamp(hexdec($hex));
|
return self::UIntToTimestamp(hexdec($hex));
|
||||||
} elseif ($type == 'Bool') {
|
} elseif ($type == 'Bool') {
|
||||||
return ($hex == "01") ? true : false;
|
return ($hex == "01") ? true : false;
|
||||||
|
Loading…
Reference in New Issue
Block a user