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: /**
12: * Analyzes US-ASCII characters.
13: * @package Swift
14: * @subpackage Encoder
15: * @author Chris Corbyn
16: */
17: class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
18: {
19: /**
20: * Returns the complete charactermap
21: *
22: * @param string $string
23: * @param int $startOffset
24: * @param string $ignoredChars
25: */
26: public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
27: {
28: $strlen=strlen($string);
29: $ignoredChars='';
30: for ($i = 0; $i < $strlen; ++$i) {
31: if ($string[$i]>"\x07F") { // Invalid char
32: $currentMap[$i+$startOffset]=$string[$i];
33: }
34: }
35:
36: return $strlen;
37: }
38:
39: /**
40: * Returns mapType
41: * @return int mapType
42: */
43: public function getMapType()
44: {
45: return self::MAP_TYPE_INVALID;
46: }
47:
48: /**
49: * Returns an integer which specifies how many more bytes to read.
50: * A positive integer indicates the number of more bytes to fetch before invoking
51: * this method again.
52: * A value of zero means this is already a valid character.
53: * A value of -1 means this cannot possibly be a valid character.
54: * @param string $bytes
55: * @return int
56: */
57: public function validateByteSequence($bytes, $size)
58: {
59: $byte = reset($bytes);
60: if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F) {
61: return 0;
62: } else {
63: return -1;
64: }
65: }
66:
67: /**
68: * Returns the number of bytes which should be read to start each character.
69: * @return int
70: */
71: public function getInitialByteSize()
72: {
73: return 1;
74: }
75: }
76: