[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/Swiftmailer/classes/Swift/CharacterReader/ -> GenericFixedWidthReader.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of SwiftMailer.
   5   * (c) 2004-2009 Chris Corbyn
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * Provides fixed-width byte sizes for reading fixed-width character sets.
  13   *
  14   * @author Chris Corbyn
  15   * @author Xavier De Cock <xdecock@gmail.com>
  16   */
  17  class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterReader
  18  {
  19      /**
  20       * The number of bytes in a single character.
  21       *
  22       * @var int
  23       */
  24      private $_width;
  25  
  26      /**
  27       * Creates a new GenericFixedWidthReader using $width bytes per character.
  28       *
  29       * @param int $width
  30       */
  31      public function __construct($width)
  32      {
  33          $this->_width = $width;
  34      }
  35  
  36      /**
  37       * Returns the complete character map.
  38       *
  39       * @param string $string
  40       * @param int    $startOffset
  41       * @param array  $currentMap
  42       * @param mixed  $ignoredChars
  43       *
  44       * @return int
  45       */
  46      public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
  47      {
  48          $strlen = strlen($string);
  49          // % and / are CPU intensive, so, maybe find a better way
  50          $ignored = $strlen % $this->_width;
  51          $ignoredChars = substr($string, -$ignored);
  52          $currentMap = $this->_width;
  53  
  54          return ($strlen - $ignored) / $this->_width;
  55      }
  56  
  57      /**
  58       * Returns the mapType.
  59       *
  60       * @return int
  61       */
  62      public function getMapType()
  63      {
  64          return self::MAP_TYPE_FIXED_LEN;
  65      }
  66  
  67      /**
  68       * Returns an integer which specifies how many more bytes to read.
  69       *
  70       * A positive integer indicates the number of more bytes to fetch before invoking
  71       * this method again.
  72       *
  73       * A value of zero means this is already a valid character.
  74       * A value of -1 means this cannot possibly be a valid character.
  75       *
  76       * @param string $bytes
  77       * @param int    $size
  78       *
  79       * @return int
  80       */
  81      public function validateByteSequence($bytes, $size)
  82      {
  83          $needed = $this->_width - $size;
  84  
  85          return ($needed > -1) ? $needed : -1;
  86      }
  87  
  88      /**
  89       * Returns the number of bytes which should be read to start each character.
  90       *
  91       * @return int
  92       */
  93      public function getInitialByteSize()
  94      {
  95          return $this->_width;
  96      }
  97  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1