UsAsciiReader.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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") {
  32. // Invalid char
  33. $currentMap[$i + $startOffset] = $string[$i];
  34. }
  35. }
  36. return $strlen;
  37. }
  38. /**
  39. * Returns mapType.
  40. *
  41. * @return int mapType
  42. */
  43. public function getMapType()
  44. {
  45. return self::MAP_TYPE_INVALID;
  46. }
  47. /**
  48. * Returns an integer which specifies how many more bytes to read.
  49. *
  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. *
  55. * @param string $bytes
  56. * @param int $size
  57. *
  58. * @return int
  59. */
  60. public function validateByteSequence($bytes, $size)
  61. {
  62. $byte = reset($bytes);
  63. if (1 == \count($bytes) && $byte >= 0x00 && $byte <= 0x7F) {
  64. return 0;
  65. }
  66. return -1;
  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. }