isHex.
This commit is contained in:
parent
c6c5cc9251
commit
ab90423aab
@ -118,7 +118,7 @@ class Utils
|
|||||||
if (!is_string($value)) {
|
if (!is_string($value)) {
|
||||||
throw new InvalidArgumentException('The value to zeroPrefixed function must be string.');
|
throw new InvalidArgumentException('The value to zeroPrefixed function must be string.');
|
||||||
}
|
}
|
||||||
return (strpos($value, '0x') === 0);
|
return (strpos($value, '0x') === 0) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,6 +178,17 @@ class Utils
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isHex
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isHex($value)
|
||||||
|
{
|
||||||
|
return (is_string($value) && preg_match('/^(0x)?[a-f0-9]*$/', $value) === 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sha3
|
* sha3
|
||||||
* keccak256
|
* keccak256
|
||||||
|
@ -366,4 +366,24 @@ class UtilsTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals($jsonArrayDepth2, $jsonAssoc);
|
$this->assertEquals($jsonArrayDepth2, $jsonAssoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testIsHex
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testIsHex()
|
||||||
|
{
|
||||||
|
$isHex = Utils::isHex($this->testHex);
|
||||||
|
|
||||||
|
$this->assertTrue($isHex);
|
||||||
|
|
||||||
|
$isHex = Utils::isHex('0x' . $this->testHex);
|
||||||
|
|
||||||
|
$this->assertTrue($isHex);
|
||||||
|
|
||||||
|
$isHex = Utils::isHex('hello world');
|
||||||
|
|
||||||
|
$this->assertFalse($isHex);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user