was.php

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 9  →  ?path2? @ 10
File deleted
/trunk/src/functions.php
/trunk/src/IO/IO.php
@@ -0,0 +1,29 @@
<?php
 
###########################################################################
## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
###########################################################################
function atomized_put_contents($file, $data) {
$fp = fopen($file, "w+");
if (flock($fp, LOCK_EX)) {
fwrite($fp, $data);
fflush($fp);
flock($fp, LOCK_UN);
}
fclose($fp);
}
###########################################################################
## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
###########################################################################
function atomized_get_contents($file) {
$fp = fopen($file, "r+");
$ct = '';
if (flock($fp, LOCK_SH)) {
if (filesize($file)) {
$ct = fread($fp, filesize($file));
}
flock($fp, LOCK_UN);
}
fclose($fp);
return $ct;
}
/trunk/src/collections/arrays/arrays.php
@@ -0,0 +1,13 @@
<?php
 
###########################################################################
## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
###########################################################################
function wasArrayStride($a, $s) {
return array_filter($a,
function($e, $i) use($s) {
return $i % $s == 0;
},
ARRAY_FILTER_USE_BOTH
);
}
/trunk/src/formats/csv/csv.php
@@ -0,0 +1,67 @@
<?php
 
###########################################################################
## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
###########################################################################
function wasCSVToArray($csv) {
$l = array();
$s = array();
$m = "";
for ($i = 0; $i < strlen($csv); ++$i) {
switch ($csv{$i}) {
case ',':
if (sizeof($s) == 0 || !current($s) == '"') {
array_push($l, $m);
$m = "";
break;
}
$m .= $csv{$i};
continue;
case '"':
if ($i + 1 < strlen($csv) && $csv{$i} == $csv{$i + 1}) {
$m .= $csv{$i};
++$i;
break;
}
if (sizeof($s) == 0|| !current($s) == $csv[$i]) {
array_push($s, $csv{$i});
continue;
}
array_pop($s);
break;
default:
$m .= $csv{$i};
break;
}
}
array_push($l, $m);
return $l;
}
 
###########################################################################
## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
###########################################################################
function wasArrayToCSV($a) {
return implode(
',',
array_map(
function($o) {
$o = str_replace('"', '""', $o);
switch(
(strpos($o, ' ') !== FALSE) ||
(strpos($o, '"') !== FALSE) ||
(strpos($o, ',') !== FALSE) ||
(strpos($o, '\r') !== FALSE) ||
(strpos($o, '\n') !== FALSE)
)
{
case TRUE:
return '"' . $o . '"';
default:
return $o;
}
},
$a
)
);
}
/trunk/src/formats/kvp/kvp.php
@@ -0,0 +1,18 @@
<?php
 
###########################################################################
## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
###########################################################################
function wasKeyValueGet($key, $data) {
return array_reduce(
explode(
"&",
$data
),
function($o, $p) {
$x = explode("=", $p);
return array_shift($x) != $o ? $o : array_shift($x);
},
$key
);
}
/trunk/src/lsl/lsl.php
@@ -0,0 +1,15 @@
<?php
 
###########################################################################
## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
###########################################################################
function wasLSLVectorToArray($vector) {
$components = array();
if(!preg_match(
"/^<\s*([0-9\.]+?)\s*,\s*([0-9\.]+?)\s*,\s*([0-9\.]+?)\s*>$/",
$vector,
$components
)) return;
array_shift($components);
return $components;
}
/trunk/src/mathematics/algebra.php
@@ -0,0 +1,20 @@
<?php
 
##########################################################################
## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
###########################################################################
function mapValueToRange($value, $xMin, $xMax, $yMin, $yMax) {
return $yMin + (
(
$yMax - $yMin
)
*
(
$value - $xMin
)
/
(
$xMax - $xMin
)
);
}