: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
+10 -39
View File
@@ -4,17 +4,17 @@
*
* @filesource AlphaNum.php
* @created 25.11.2015
* @package codemasher\QRCode\Data
* @package chillerlan\QRCode\Data
* @author Smiley <smiley@chillerlan.net>
* @copyright 2015 Smiley
* @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;
/**
*
@@ -22,7 +22,7 @@ use codemasher\QRCode\QRConst;
class AlphaNum extends QRDataBase implements QRDataInterface{
/**
* @var
* @var int
*/
public $mode = QRConst::MODE_ALPHANUM;
@@ -32,47 +32,18 @@ class AlphaNum extends QRDataBase implements QRDataInterface{
protected $lengthBits = [9, 11, 13];
/**
* @param $buffer
* @param \chillerlan\QRCode\BitBuffer $buffer
*/
public function write(BitBuffer &$buffer){
$i = 0;
while($i + 1 < $this->dataLength){
$buffer->put($this->getCode(ord($this->data[$i])) * 45 + $this->getCode(ord($this->data[$i + 1])), 11);
$buffer->put(Util::getCharCode($this->data[$i]) * 45 + Util::getCharCode($this->data[$i + 1]), 11);
$i += 2;
}
if($i < $this->dataLength){
$buffer->put($this->getCode(ord($this->data[$i])), 6);
}
}
/**
* @param $c
*
* @return int
* @throws \codemasher\QRCode\QRCodeException
*/
protected function getCode($c){
switch(true){
case ord('0') <= $c && $c <= ord('9'): return $c - ord('0');
case ord('A') <= $c && $c <= ord('Z'): return $c - ord('A') + 10;
default:
switch($c){
case ord(' '): return 36;
case ord('$'): return 37;
case ord('%'): return 38;
case ord('*'): return 39;
case ord('+'): return 40;
case ord('-'): return 41;
case ord('.'): return 42;
case ord('/'): return 43;
case ord(':'): return 44;
default:
throw new QRCodeException('illegal char: '.$c);
}
$buffer->put(Util::getCharCode($this->data[$i]), 6);
}
}