TYPO3  7.6
GenericFixedWidthReader.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of SwiftMailer.
5  * (c) 2004-2009 Chris Corbyn
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10 
18 {
24  private $_width;
25 
31  public function __construct($width)
32  {
33  $this->_width = $width;
34  }
35 
46  public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
47  {
48  $strlen = strlen($string);
49  // % and / are CPU intensive, so, maybe find a better way
50  $ignored = $strlen % $this->_width;
51  $ignoredChars = substr($string, -$ignored);
52  $currentMap = $this->_width;
53 
54  return ($strlen - $ignored) / $this->_width;
55  }
56 
62  public function getMapType()
63  {
64  return self::MAP_TYPE_FIXED_LEN;
65  }
66 
81  public function validateByteSequence($bytes, $size)
82  {
83  $needed = $this->_width - $size;
84 
85  return ($needed > -1) ? $needed : -1;
86  }
87 
93  public function getInitialByteSize()
94  {
95  return $this->_width;
96  }
97 }