UsAsciiReader.php 1.8KB

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