|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* 00004 * This file is part of SwiftMailer. 00005 * (c) 2004-2009 Chris Corbyn 00006 * 00007 * For the full copyright and license information, please view the LICENSE 00008 * file that was distributed with this source code. 00009 */ 00010 00011 //@require 'Swift/CharacterReader.php'; 00012 00013 /** 00014 * Provides fixed-width byte sizes for reading fixed-width character sets. 00015 * @package Swift 00016 * @subpackage Encoder 00017 * @author Chris Corbyn 00018 * @author Xavier De Cock <xdecock@gmail.com> 00019 */ 00020 class Swift_CharacterReader_GenericFixedWidthReader 00021 implements Swift_CharacterReader 00022 { 00023 00024 /** 00025 * The number of bytes in a single character. 00026 * @var int 00027 * @access private 00028 */ 00029 private $_width; 00030 00031 /** 00032 * Creates a new GenericFixedWidthReader using $width bytes per character. 00033 * @param int $width 00034 */ 00035 public function __construct($width) 00036 { 00037 $this->_width = $width; 00038 } 00039 00040 /** 00041 * Returns the complete charactermap 00042 * 00043 * @param string $string 00044 * @param int $startOffset 00045 * @param array $currentMap 00046 * @param mixed $ignoredChars 00047 * @return $int 00048 */ 00049 public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) 00050 { 00051 $strlen = strlen($string); 00052 // % and / are CPU intensive, so, maybe find a better way 00053 $ignored = $strlen%$this->_width; 00054 $ignoredChars = substr($string, - $ignored); 00055 $currentMap = $this->_width; 00056 return ($strlen - $ignored)/$this->_width; 00057 00058 } 00059 00060 /** 00061 * Returns mapType 00062 * @int mapType 00063 */ 00064 public function getMapType() 00065 { 00066 return self::MAP_TYPE_FIXED_LEN; 00067 } 00068 00069 /** 00070 * Returns an integer which specifies how many more bytes to read. 00071 * A positive integer indicates the number of more bytes to fetch before invoking 00072 * this method again. 00073 * A value of zero means this is already a valid character. 00074 * A value of -1 means this cannot possibly be a valid character. 00075 * @param string $bytes 00076 * @return int 00077 */ 00078 public function validateByteSequence($bytes, $size) 00079 { 00080 $needed = $this->_width - $size; 00081 return ($needed > -1) 00082 ? $needed 00083 : -1 00084 ; 00085 } 00086 00087 /** 00088 * Returns the number of bytes which should be read to start each character. 00089 * @return int 00090 */ 00091 public function getInitialByteSize() 00092 { 00093 return $this->_width; 00094 } 00095 00096 }
1.8.0