From: Roland Häder Date: Sat, 19 May 2012 15:30:33 +0000 (+0000) Subject: Added hexval() which really stupid regex X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=957fde994a61abfe5deb2b914c4e9d24e2f462b1;p=core.git Added hexval() which really stupid regex --- diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index b3ad65ff..4b2812dc 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -1004,6 +1004,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return void */ public final function setSocketResource ($socketResource) { + //* NOISY-DEBUG: */ $this->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource=' . $socketResource . ',previous[' . gettype($this->socketResource) . ']=' . $this->socketResource); $this->socketResource = $socketResource; } @@ -1012,7 +1013,8 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * * @return $socketResource A valid socket resource */ - public function getSocketResource () { + public final function getSocketResource () { + //* NOISY-DEBUG: */ $this->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource[' . gettype($this->socketResource) . ']=' . $this->socketResource); return $this->socketResource; } @@ -2042,6 +2044,27 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Return result return $ret; } + + /** + * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f). + * + * @param $num A string consisting only chars between 0 and 9 + * @param $assertMismatch Whether to assert mismatches + * @return $ret The (hopefully) secured hext-numbered value + */ + public function hexval ($num, $assertMismatch = false) { + // Filter all numbers out + $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num); + + // Assert only if requested + if ($assertMismatch === true) { + // Has the whole value changed? + assert(('' . $ret . '' != '' . $num . '') && (!is_null($num))); + } // END - if + + // Return result + return $ret; + } } // [EOF]