:godmode:

This commit is contained in:
smiley
2015-12-08 04:02:13 +01:00
parent 8671a6936a
commit e21a7da686
14 changed files with 678 additions and 883 deletions
+9 -42
View File
@@ -10,11 +10,11 @@
* @license MIT
*/
namespace codemasher\QRCode\Data;
namespace chillerlan\QRCode\Data;
use codemasher\QRCode\BitBuffer;
use codemasher\QRCode\QRCodeException;
use codemasher\QRCode\QRConst;
use chillerlan\QRCode\BitBuffer;
use chillerlan\QRCode\QRConst;
use chillerlan\QRCode\Util;
/**
*
@@ -32,60 +32,27 @@ class Number extends QRDataBase implements QRDataInterface{
protected $lengthBits = [10, 12, 14];
/**
* @param $buffer
*
* @return $this
* @param \chillerlan\QRCode\BitBuffer $buffer
*/
public function write(BitBuffer &$buffer){
$i = 0;
while($i + 2 < $this->dataLength){
$num = $this->parseInt(substr($this->data, $i, 3));
$buffer->put($num, 10);
$buffer->put(Util::parseInt(substr($this->data, $i, 3)), 10);
$i += 3;
}
if($i < $this->dataLength){
if($this->dataLength - $i === 1){
$num = $this->parseInt(substr($this->data, $i, $i + 1));
$buffer->put($num, 4);
$buffer->put(Util::parseInt(substr($this->data, $i, $i + 1)), 4);
}
else if($this->dataLength - $i === 2){
$num = $this->parseInt(substr($this->data, $i, $i + 2));
$buffer->put($num, 7);
$buffer->put(Util::parseInt(substr($this->data, $i, $i + 2)), 7);
}
}
return $this;
}
/**
* @param string $string
*
* @return int
* @throws \codemasher\QRCode\QRCodeException
*/
protected function parseInt($string){
$num = 0;
$len = strlen($string);
for($i = 0; $i < $len; $i++){
$c = ord($string[$i]);
$ord0 = ord('0');
if(ord('0') <= $c && $c <= ord('9')){
$c = $c - $ord0;
}
else{
throw new QRCodeException('illegal char: '.$c);
}
$num = $num * 10 + $c;
}
return $num;
}
}