UsAsciiReader.php 1.7KB

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