UsAsciiReader.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2004-2009 Chris Corbyn
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * Analyzes US-ASCII characters.
  11. *
  12. * @package Swift
  13. * @subpackage Encoder
  14. * @author Chris Corbyn
  15. */
  16. class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
  17. {
  18. /**
  19. * Returns the complete character map.
  20. *
  21. * @param string $string
  22. * @param integer $startOffset
  23. * @param array $currentMap
  24. * @param string $ignoredChars
  25. *
  26. * @return integer
  27. */
  28. public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
  29. {
  30. $strlen=strlen($string);
  31. $ignoredChars='';
  32. for ($i = 0; $i < $strlen; ++$i) {
  33. if ($string[$i]>"\x07F") { // Invalid char
  34. $currentMap[$i+$startOffset]=$string[$i];
  35. }
  36. }
  37. return $strlen;
  38. }
  39. /**
  40. * Returns mapType
  41. *
  42. * @return integer mapType
  43. */
  44. public function getMapType()
  45. {
  46. return self::MAP_TYPE_INVALID;
  47. }
  48. /**
  49. * Returns an integer which specifies how many more bytes to read.
  50. *
  51. * A positive integer indicates the number of more bytes to fetch before invoking
  52. * this method again.
  53. * A value of zero means this is already a valid character.
  54. * A value of -1 means this cannot possibly be a valid character.
  55. *
  56. * @param string $bytes
  57. * @param integer $size
  58. *
  59. * @return integer
  60. */
  61. public function validateByteSequence($bytes, $size)
  62. {
  63. $byte = reset($bytes);
  64. if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F) {
  65. return 0;
  66. } else {
  67. return -1;
  68. }
  69. }
  70. /**
  71. * Returns the number of bytes which should be read to start each character.
  72. *
  73. * @return integer
  74. */
  75. public function getInitialByteSize()
  76. {
  77. return 1;
  78. }
  79. }