:suspect:

This commit is contained in:
smiley
2015-12-02 03:49:21 +01:00
parent b8606b24da
commit 20649ec13a
11 changed files with 362 additions and 224 deletions
+20 -38
View File
@@ -23,32 +23,26 @@ use codemasher\QRCode\QRConst;
*/
class AlphaNum extends QRDataBase implements QRDataInterface{
/**
* AlphaNum constructor.
*
* @param $data
* @var
*/
public function __construct($data){
parent::__construct($data, QRConst::MODE_ALPHA_NUM);
}
protected $mode = QRConst::MODE_ALPHA_NUM;
/**
* @param $buffer
*/
public function write(BitBuffer &$buffer){
$data = $this->getData();
$i = 0;
$c = $this->getData();
while($i + 1 < strlen($c)){
$buffer->put($this->getCode(ord($c[$i])) * 45
+ $this->getCode(ord($c[$i + 1])), 11);
$len = strlen($data);
while($i + 1 < $len){
$buffer->put($this->getCode(ord($data[$i])) * 45 + $this->getCode(ord($data[$i + 1])), 11);
$i += 2;
}
if($i < strlen($c)){
$buffer->put($this->getCode(ord($c[$i])), 6);
if($i < $len){
$buffer->put($this->getCode(ord($data[$i])), 6);
}
}
@@ -67,40 +61,28 @@ class AlphaNum extends QRDataBase implements QRDataInterface{
*/
protected function getCode($c){
if($this->util->toCharCode('0') <= $c
&& $c <= $this->util->toCharCode('9')
){
if($this->util->toCharCode('0') <= $c && $c <= $this->util->toCharCode('9')){
return $c - $this->util->toCharCode('0');
}
else if($this->util->toCharCode('A') <= $c
&& $c <= $this->util->toCharCode('Z')
){
else if($this->util->toCharCode('A') <= $c && $c <= $this->util->toCharCode('Z')){
return $c - $this->util->toCharCode('A') + 10;
}
else{
switch($c){
case $this->util->toCharCode(' ') :
return 36;
case $this->util->toCharCode('$') :
return 37;
case $this->util->toCharCode('%') :
return 38;
case $this->util->toCharCode('*') :
return 39;
case $this->util->toCharCode('+') :
return 40;
case $this->util->toCharCode('-') :
return 41;
case $this->util->toCharCode('.') :
return 42;
case $this->util->toCharCode('/') :
return 43;
case $this->util->toCharCode(':') :
return 44;
case $this->util->toCharCode(' '): return 36;
case $this->util->toCharCode('$'): return 37;
case $this->util->toCharCode('%'): return 38;
case $this->util->toCharCode('*'): return 39;
case $this->util->toCharCode('+'): return 40;
case $this->util->toCharCode('-'): return 41;
case $this->util->toCharCode('.'): return 42;
case $this->util->toCharCode('/'): return 43;
case $this->util->toCharCode(':'): return 44;
default :
throw new QRCodeException('illegal char: '.$c);
}
}
}
}