mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-24 22:17:53 +00:00
refactoring
This commit is contained in:
+31
-4
@@ -13,8 +13,8 @@
|
||||
namespace chillerlan\QRCode\Data;
|
||||
|
||||
use chillerlan\QRCode\BitBuffer;
|
||||
use chillerlan\QRCode\QRCodeException;
|
||||
use chillerlan\QRCode\QRConst;
|
||||
use chillerlan\QRCode\Util;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -38,21 +38,48 @@ class Number extends QRDataBase implements QRDataInterface{
|
||||
$i = 0;
|
||||
|
||||
while($i + 2 < $this->dataLength){
|
||||
$buffer->put(Util::parseInt(substr($this->data, $i, 3)), 10);
|
||||
$buffer->put($this->parseInt(substr($this->data, $i, 3)), 10);
|
||||
$i += 3;
|
||||
}
|
||||
|
||||
if($i < $this->dataLength){
|
||||
|
||||
if($this->dataLength - $i === 1){
|
||||
$buffer->put(Util::parseInt(substr($this->data, $i, $i + 1)), 4);
|
||||
$buffer->put($this->parseInt(substr($this->data, $i, $i + 1)), 4);
|
||||
}
|
||||
else if($this->dataLength - $i === 2){
|
||||
$buffer->put(Util::parseInt(substr($this->data, $i, $i + 2)), 7);
|
||||
$buffer->put($this->parseInt(substr($this->data, $i, $i + 2)), 7);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return int
|
||||
* @throws \chillerlan\QRCode\QRCodeException
|
||||
*/
|
||||
private static function parseInt($string){
|
||||
$num = 0;
|
||||
|
||||
$len = strlen($string);
|
||||
for($i = 0; $i < $len; $i++){
|
||||
$c = ord($string[$i]);
|
||||
$ord0 = ord('0');
|
||||
|
||||
if($ord0 <= $c && $c <= ord('9')){
|
||||
$c = $c - $ord0;
|
||||
}
|
||||
else{
|
||||
throw new QRCodeException('illegal char: '.$c);
|
||||
}
|
||||
|
||||
$num = $num * 10 + $c;
|
||||
}
|
||||
|
||||
return $num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user