/framework/vendor/swift/lib/classes/Swift/CharacterReader/UsAsciiReader.php

http://zoop.googlecode.com/ · PHP · 83 lines · 38 code · 7 blank · 38 comment · 6 complexity · b658f2243c8dc8b559afe6d3dd7ac1cf MD5 · raw file

  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. //@require 'Swift/CharacterReader.php';
  10. /**
  11. * Analyzes US-ASCII characters.
  12. * @package Swift
  13. * @subpackage Encoder
  14. * @author Chris Corbyn
  15. */
  16. class Swift_CharacterReader_UsAsciiReader
  17. implements Swift_CharacterReader
  18. {
  19. /**
  20. * Returns the complete charactermap
  21. *
  22. * @param string $string
  23. * @param int $startOffset
  24. * @param string $ignoredChars
  25. */
  26. public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
  27. {
  28. $strlen=strlen($string);
  29. $ignoredChars='';
  30. for( $i = 0; $i < $strlen; ++$i)
  31. {
  32. if ($string[$i]>"\x07F")
  33. { // Invalid char
  34. $currentMap[$i+$startOffset]=$string[$i];
  35. }
  36. }
  37. return $strlen;
  38. }
  39. /**
  40. * Returns mapType
  41. * @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. * 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. * @param string $bytes
  54. * @return int
  55. */
  56. public function validateByteSequence($bytes, $size)
  57. {
  58. $byte = reset($bytes);
  59. if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F)
  60. {
  61. return 0;
  62. }
  63. else
  64. {
  65. return -1;
  66. }
  67. }
  68. /**
  69. * Returns the number of bytes which should be read to start each character.
  70. * @return int
  71. */
  72. public function getInitialByteSize()
  73. {
  74. return 1;
  75. }
  76. }