]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/utils/string/class_StringUtils.php
Continued:
[core.git] / framework / main / classes / utils / string / class_StringUtils.php
index d895d1911d15ab342cff8262bdde2ffa714e3009..e6c4c738cfc6364d98b297e3cf875ab14d075e39 100644 (file)
@@ -422,4 +422,25 @@ final class StringUtils extends BaseFrameworkSystem {
                return $packed;
        }
 
+       /**
+        * 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 static function hexval (string $num, bool $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)));
+               }
+
+               // Return result
+               return $ret;
+       }
+
 }