UsAsciiReader.php 1.9 KB

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. *
  12. * @author Chris Corbyn
  13. */
  14. class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
  15. {
  16. /**
  17. * Returns the complete character map.
  18. *
  19. * @param string $string
  20. * @param int $startOffset
  21. * @param array $currentMap
  22. * @param string $ignoredChars
  23. *
  24. * @return int
  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. return $strlen;
  36. }
  37. /**
  38. * Returns mapType
  39. *
  40. * @return 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. *
  49. * A positive integer indicates the number of more bytes to fetch before invoking
  50. * this method again.
  51. * A value of zero means this is already a valid character.
  52. * A value of -1 means this cannot possibly be a valid character.
  53. *
  54. * @param string $bytes
  55. * @param int $size
  56. *
  57. * @return int
  58. */
  59. public function validateByteSequence($bytes, $size)
  60. {
  61. $byte = reset($bytes);
  62. if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F) {
  63. return 0;
  64. } else {
  65. return -1;
  66. }
  67. }
  68. /**
  69. * Returns the number of bytes which should be read to start each character.
  70. *
  71. * @return int
  72. */
  73. public function getInitialByteSize()
  74. {
  75. return 1;
  76. }
  77. }