mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-29 19:48:17 +00:00
:suspect:
This commit is contained in:
+20
-38
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user