mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-10-14 15:57:13 +00:00
:octocat: added Number::CHAR_MAP and simplified QRCode::isNumber (...)
This commit is contained in:
+14
-11
@@ -273,16 +273,7 @@ class QRCode{
|
||||
* @return bool
|
||||
*/
|
||||
public function isNumber(string $string):bool {
|
||||
$len = strlen($string);
|
||||
$map = str_split('0123456789');
|
||||
|
||||
for($i = 0; $i < $len; $i++){
|
||||
if(!in_array($string[$i], $map, true)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return $this->checkString($string, Number::CHAR_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,10 +284,22 @@ class QRCode{
|
||||
* @return bool
|
||||
*/
|
||||
public function isAlphaNum(string $string):bool {
|
||||
return $this->checkString($string, AlphaNum::CHAR_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks is a given $string matches the characters of a given $charmap, returns false on the first invalid occurence.
|
||||
*
|
||||
* @param string $string
|
||||
* @param array $charmap
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkString(string $string, array $charmap):bool{
|
||||
$len = strlen($string);
|
||||
|
||||
for($i = 0; $i < $len; $i++){
|
||||
if(!in_array($string[$i], AlphaNum::CHAR_MAP, true)){
|
||||
if(!in_array($string[$i], $charmap, true)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user