Added feature #15998: Create a new API to send mails based on SwiftMailer to replace...
[Packages/TYPO3.CMS.git] / typo3 / contrib / swiftmailer / classes / Swift / CharacterReader / GenericFixedWidthReader.php
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
11 //@require 'Swift/CharacterReader.php';
12
13 /**
14 * Provides fixed-width byte sizes for reading fixed-width character sets.
15 * @package Swift
16 * @subpackage Encoder
17 * @author Chris Corbyn
18 * @author Xavier De Cock <xdecock@gmail.com>
19 */
20 class Swift_CharacterReader_GenericFixedWidthReader
21 implements Swift_CharacterReader
22 {
23
24 /**
25 * The number of bytes in a single character.
26 * @var int
27 * @access private
28 */
29 private $_width;
30
31 /**
32 * Creates a new GenericFixedWidthReader using $width bytes per character.
33 * @param int $width
34 */
35 public function __construct($width)
36 {
37 $this->_width = $width;
38 }
39
40 /**
41 * Returns the complete charactermap
42 *
43 * @param string $string
44 * @param int $startOffset
45 * @param array $currentMap
46 * @param mixed $ignoredChars
47 * @return $int
48 */
49 public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
50 {
51 $strlen = strlen($string);
52 // % and / are CPU intensive, so, maybe find a better way
53 $ignored = $strlen%$this->_width;
54 $ignoredChars = substr($string, - $ignored);
55 $currentMap = $this->_width;
56 return ($strlen - $ignored)/$this->_width;
57
58 }
59
60 /**
61 * Returns mapType
62 * @int mapType
63 */
64 public function getMapType()
65 {
66 return self::MAP_TYPE_FIXED_LEN;
67 }
68
69 /**
70 * Returns an integer which specifies how many more bytes to read.
71 * A positive integer indicates the number of more bytes to fetch before invoking
72 * this method again.
73 * A value of zero means this is already a valid character.
74 * A value of -1 means this cannot possibly be a valid character.
75 * @param string $bytes
76 * @return int
77 */
78 public function validateByteSequence($bytes, $size)
79 {
80 $needed = $this->_width - $size;
81 return ($needed > -1)
82 ? $needed
83 : -1
84 ;
85 }
86
87 /**
88 * Returns the number of bytes which should be read to start each character.
89 * @return int
90 */
91 public function getInitialByteSize()
92 {
93 return $this->_width;
94 }
95
96 }