]>
Raphaƫl G. Git Repositories - cdn/blob - vendor/phpqrcode/qrsplit.php
   5  * Input splitting classes 
   7  * Based on libqrencode C library distributed under LGPL 2.1 
   8  * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net> 
  10  * PHP QR Code is distributed under LGPL 3 
  11  * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> 
  13  * The following data / specifications are taken from 
  14  * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) 
  16  * "Automatic identification and data capture techniques -- 
  17  *  QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) 
  19  * This library is free software; you can redistribute it and/or 
  20  * modify it under the terms of the GNU Lesser General Public 
  21  * License as published by the Free Software Foundation; either 
  22  * version 3 of the License, or any later version. 
  24  * This library is distributed in the hope that it will be useful, 
  25  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
  27  * Lesser General Public License for more details. 
  29  * You should have received a copy of the GNU Lesser General Public 
  30  * License along with this library; if not, write to the Free Software 
  31  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 
  39         //---------------------------------------------------------------------- 
  40         public function __construct($dataStr, $input, $modeHint) 
  42             $this->dataStr  
= $dataStr; 
  43             $this->input    
= $input; 
  44             $this->modeHint 
= $modeHint; 
  47         //---------------------------------------------------------------------- 
  48         public static function isdigitat($str, $pos) 
  50             if ($pos >= strlen($str)) 
  53             return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); 
  56         //---------------------------------------------------------------------- 
  57         public static function isalnumat($str, $pos) 
  59             if ($pos >= strlen($str)) 
  62             return (QRinput
::lookAnTable(ord($str[$pos])) >= 0); 
  65         //---------------------------------------------------------------------- 
  66         public function identifyMode($pos) 
  68             if ($pos >= strlen($this->dataStr
)) 
  71             $c = $this->dataStr
[$pos]; 
  73             if(self
::isdigitat($this->dataStr
, $pos)) { 
  75             } else if(self
::isalnumat($this->dataStr
, $pos)) { 
  77             } else if($this->modeHint 
== QR_MODE_KANJI
) { 
  79                 if ($pos+
1 < strlen($this->dataStr
)) 
  81                     $d = $this->dataStr
[$pos+
1]; 
  82                     $word = (ord($c) << 8) | ord($d); 
  83                     if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { 
  92         //---------------------------------------------------------------------- 
  93         public function eatNum() 
  95             $ln = QRspec
::lengthIndicator(QR_MODE_NUM
, $this->input
->getVersion()); 
  98             while(self
::isdigitat($this->dataStr
, $p)) { 
 103             $mode = $this->identifyMode($p); 
 105             if($mode == QR_MODE_8
) { 
 106                 $dif = QRinput
::estimateBitsModeNum($run) + 
4 + 
$ln 
 107                      + QRinput
::estimateBitsMode8(1)         // + 4 + l8 
 108                      - QRinput
::estimateBitsMode8($run + 
1); // - 4 - l8 
 110                     return $this->eat8(); 
 113             if($mode == QR_MODE_AN
) { 
 114                 $dif = QRinput
::estimateBitsModeNum($run) + 
4 + 
$ln 
 115                      + QRinput
::estimateBitsModeAn(1)        // + 4 + la 
 116                      - QRinput
::estimateBitsModeAn($run + 
1);// - 4 - la 
 118                     return $this->eatAn(); 
 122             $ret = $this->input
->append(QR_MODE_NUM
, $run, str_split($this->dataStr
)); 
 129         //---------------------------------------------------------------------- 
 130         public function eatAn() 
 132             $la = QRspec
::lengthIndicator(QR_MODE_AN
,  $this->input
->getVersion()); 
 133             $ln = QRspec
::lengthIndicator(QR_MODE_NUM
, $this->input
->getVersion()); 
 137             while(self
::isalnumat($this->dataStr
, $p)) { 
 138                 if(self
::isdigitat($this->dataStr
, $p)) { 
 140                     while(self
::isdigitat($this->dataStr
, $q)) { 
 144                     $dif = QRinput
::estimateBitsModeAn($p) // + 4 + la 
 145                          + QRinput
::estimateBitsModeNum($q - $p) + 
4 + 
$ln 
 146                          - QRinput
::estimateBitsModeAn($q); // - 4 - la 
 160             if(!self
::isalnumat($this->dataStr
, $p)) { 
 161                 $dif = QRinput
::estimateBitsModeAn($run) + 
4 + 
$la 
 162                      + QRinput
::estimateBitsMode8(1) // + 4 + l8 
 163                       - QRinput
::estimateBitsMode8($run + 
1); // - 4 - l8 
 165                     return $this->eat8(); 
 169             $ret = $this->input
->append(QR_MODE_AN
, $run, str_split($this->dataStr
)); 
 176         //---------------------------------------------------------------------- 
 177         public function eatKanji() 
 181             while($this->identifyMode($p) == QR_MODE_KANJI
) { 
 185             $ret = $this->input
->append(QR_MODE_KANJI
, $p, str_split($this->dataStr
)); 
 192         //---------------------------------------------------------------------- 
 193         public function eat8() 
 195             $la = QRspec
::lengthIndicator(QR_MODE_AN
, $this->input
->getVersion()); 
 196             $ln = QRspec
::lengthIndicator(QR_MODE_NUM
, $this->input
->getVersion()); 
 199             $dataStrLen = strlen($this->dataStr
); 
 201             while($p < $dataStrLen) { 
 203                 $mode = $this->identifyMode($p); 
 204                 if($mode == QR_MODE_KANJI
) { 
 207                 if($mode == QR_MODE_NUM
) { 
 209                     while(self
::isdigitat($this->dataStr
, $q)) { 
 212                     $dif = QRinput
::estimateBitsMode8($p) // + 4 + l8 
 213                          + QRinput
::estimateBitsModeNum($q - $p) + 
4 + 
$ln 
 214                          - QRinput
::estimateBitsMode8($q); // - 4 - l8 
 220                 } else if($mode == QR_MODE_AN
) { 
 222                     while(self
::isalnumat($this->dataStr
, $q)) { 
 225                     $dif = QRinput
::estimateBitsMode8($p)  // + 4 + l8 
 226                          + QRinput
::estimateBitsModeAn($q - $p) + 
4 + 
$la 
 227                          - QRinput
::estimateBitsMode8($q); // - 4 - l8 
 239             $ret = $this->input
->append(QR_MODE_8
, $run, str_split($this->dataStr
)); 
 247         //---------------------------------------------------------------------- 
 248         public function splitString() 
 250             while (strlen($this->dataStr
) > 0) 
 252                 if($this->dataStr 
== '') 
 255                 $mode = $this->identifyMode(0); 
 258                     case QR_MODE_NUM
: $length = $this->eatNum(); break; 
 259                     case QR_MODE_AN
:  $length = $this->eatAn(); break; 
 261                         if ($mode == QR_MODE_KANJI
) 
 262                                 $length = $this->eatKanji(); 
 263                         else    $length = $this->eat8(); 
 265                     default: $length = $this->eat8(); break; 
 269                 if($length == 0) return 0; 
 270                 if($length < 0)  return -1; 
 272                 $this->dataStr 
= substr($this->dataStr
, $length); 
 276         //---------------------------------------------------------------------- 
 277         public function toUpper() 
 279             $stringLen = strlen($this->dataStr
); 
 282             while ($p<$stringLen) { 
 283                 $mode = self
::identifyMode(substr($this->dataStr
, $p)); 
 284                 if($mode == QR_MODE_KANJI
) { 
 287                     if (ord($this->dataStr
[$p]) >= ord('a') && ord($this->dataStr
[$p]) <= ord('z')) { 
 288                         $this->dataStr
[$p] = chr(ord($this->dataStr
[$p]) - 32); 
 294             return $this->dataStr
; 
 297         //---------------------------------------------------------------------- 
 298         public static function splitStringToQRinput($string, QRinput 
$input, $modeHint, $casesensitive = true) 
 300             if(is_null($string) || $string == '\0' || $string == '') { 
 301                 throw new Exception('empty string!!!'); 
 304             $split = new QRsplit($string, $input, $modeHint); 
 309             return $split->splitString();