Just optimisations

This commit is contained in:
Deon George
2019-05-20 17:18:18 +10:00
parent 9317f78a3a
commit df849c0cfd
12 changed files with 877 additions and 519 deletions

View File

@@ -51,4 +51,59 @@ if (! function_exists('hex_dump')) {
return $result;
}
}
/**
* Split out an FTN address into its parts
*
* This function takes a fully qualified FTN address and splits it out into
* its components:
* Z:N/F.P@D
*/
if (! function_exists('ftn_address_split')) {
function ftn_address_split(string $address,$key=NULL)
{
if ($key AND ! in_array($key,['z','n','f','p','d']))
{
throw new \Exception('Unknown key :'.$key.' for '.$address);
}
//$data = "10:12/909";
//$data = "10:12/909.5";
//$data = "10:12/909@foo";
//$data = "10:12/909.5@foo";
$z = substr($address,0,strpos($address,':'));
if ($key == 'z')
return $z;
$x = strpos($address,':')+1;
$n = substr($address,$x,strpos($address,'/')-$x);
if ($key == 'n')
return $n;
$x = strpos($address,'/')+1;
$f = substr($address,$x,
(strpos($address,'.') ?:
(strpos($address,'@') ?: strlen($address)))-$x);
if ($key == 'f')
return $f;
$x = strpos($address,'.');
$p = $x ? substr($address,$x+1,(strpos($address,'@') ?: strlen($address))-$x-1) : 0;
if ($key == 'p')
return $p;
// @todo We dont handle domain yet.
$x = strpos($address,'@');
$d = $x ? substr($address,$x+1) : NULL;
if ($key == 'd')
return $d;
return ['z'=>$z,'n'=>$n,'f'=>$f,'p'=>$p,'d'=>$d];
}
}