diff options
author | Yuchen Pei <hi@ypei.me> | 2021-10-14 15:16:42 +1100 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2021-10-14 15:16:42 +1100 |
commit | 07f5140771388c9e0c8a99b0dd2e5d950bdb173b (patch) | |
tree | 323c00faef1edc7dea2e88ff581cc2258b2b6432 /h-source/External/swiftmailer/lib/classes/Swift/CharacterStream | |
parent | e119be145500700f3c465e12664403a07530a421 (diff) |
moving h-source subdir out.
Diffstat (limited to 'h-source/External/swiftmailer/lib/classes/Swift/CharacterStream')
2 files changed, 0 insertions, 619 deletions
diff --git a/h-source/External/swiftmailer/lib/classes/Swift/CharacterStream/ArrayCharacterStream.php b/h-source/External/swiftmailer/lib/classes/Swift/CharacterStream/ArrayCharacterStream.php deleted file mode 100755 index 9612365..0000000 --- a/h-source/External/swiftmailer/lib/classes/Swift/CharacterStream/ArrayCharacterStream.php +++ /dev/null @@ -1,319 +0,0 @@ -<?php - -/* - * This file is part of SwiftMailer. - * (c) 2004-2009 Chris Corbyn - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -//@require 'Swift/CharacterStream.php'; -//@require 'Swift/OutputByteStream.php'; - - -/** - * A CharacterStream implementation which stores characters in an internal array. - * @package Swift - * @subpackage CharacterStream - * @author Chris Corbyn - */ -class Swift_CharacterStream_ArrayCharacterStream - implements Swift_CharacterStream -{ - - /** A map of byte values and their respective characters */ - private static $_charMap; - - /** A map of characters and their derivative byte values */ - private static $_byteMap; - - /** The char reader (lazy-loaded) for the current charset */ - private $_charReader; - - /** A factory for creatiing CharacterReader instances */ - private $_charReaderFactory; - - /** The character set this stream is using */ - private $_charset; - - /** Array of characters */ - private $_array = array(); - - /** Size of the array of character */ - private $_array_size = array(); - - /** The current character offset in the stream */ - private $_offset = 0; - - /** - * Create a new CharacterStream with the given $chars, if set. - * @param Swift_CharacterReaderFactory $factory for loading validators - * @param string $charset used in the stream - */ - public function __construct(Swift_CharacterReaderFactory $factory, - $charset) - { - self::_initializeMaps(); - $this->setCharacterReaderFactory($factory); - $this->setCharacterSet($charset); - } - - /** - * Set the character set used in this CharacterStream. - * @param string $charset - */ - public function setCharacterSet($charset) - { - $this->_charset = $charset; - $this->_charReader = null; - } - - /** - * Set the CharacterReaderFactory for multi charset support. - * @param Swift_CharacterReaderFactory $factory - */ - public function setCharacterReaderFactory( - Swift_CharacterReaderFactory $factory) - { - $this->_charReaderFactory = $factory; - } - - /** - * Overwrite this character stream using the byte sequence in the byte stream. - * @param Swift_OutputByteStream $os output stream to read from - */ - public function importByteStream(Swift_OutputByteStream $os) - { - if (!isset($this->_charReader)) - { - $this->_charReader = $this->_charReaderFactory - ->getReaderFor($this->_charset); - } - - $startLength = $this->_charReader->getInitialByteSize(); - while (false !== $bytes = $os->read($startLength)) - { - $c = array(); - for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) - { - $c[] = self::$_byteMap[$bytes[$i]]; - } - $size = count($c); - $need = $this->_charReader - ->validateByteSequence($c, $size); - if ($need > 0 && - false !== $bytes = $os->read($need)) - { - for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) - { - $c[] = self::$_byteMap[$bytes[$i]]; - } - } - $this->_array[] = $c; - ++$this->_array_size; - } - } - - /** - * Import a string a bytes into this CharacterStream, overwriting any existing - * data in the stream. - * @param string $string - */ - public function importString($string) - { - $this->flushContents(); - $this->write($string); - } - - /** - * Read $length characters from the stream and move the internal pointer - * $length further into the stream. - * @param int $length - * @return string - */ - public function read($length) - { - if ($this->_offset == $this->_array_size) - { - return false; - } - - // Don't use array slice - $arrays = array(); - $end = $length + $this->_offset; - for ($i = $this->_offset; $i < $end; ++$i) - { - if (!isset($this->_array[$i])) - { - break; - } - $arrays[] = $this->_array[$i]; - } - $this->_offset += $i - $this->_offset; // Limit function calls - $chars = false; - foreach ($arrays as $array) - { - $chars .= implode('', array_map('chr', $array)); - } - return $chars; - } - - /** - * Read $length characters from the stream and return a 1-dimensional array - * containing there octet values. - * @param int $length - * @return int[] - */ - public function readBytes($length) - { - if ($this->_offset == $this->_array_size) - { - return false; - } - $arrays = array(); - $end = $length + $this->_offset; - for ($i = $this->_offset; $i < $end; ++$i) - { - if (!isset($this->_array[$i])) - { - break; - } - $arrays[] = $this->_array[$i]; - } - $this->_offset += ($i - $this->_offset); // Limit function calls - return call_user_func_array('array_merge', $arrays); - } - - /** - * Write $chars to the end of the stream. - * @param string $chars - */ - public function write($chars) - { - if (!isset($this->_charReader)) - { - $this->_charReader = $this->_charReaderFactory->getReaderFor( - $this->_charset); - } - - $startLength = $this->_charReader->getInitialByteSize(); - - $fp = fopen('php://memory', 'w+b'); - fwrite($fp, $chars); - unset($chars); - fseek($fp, 0, SEEK_SET); - - $buffer = array(0); - $buf_pos = 1; - $buf_len = 1; - $has_datas = true; - do - { - $bytes = array(); - // Buffer Filing - if ($buf_len - $buf_pos < $startLength) - { - $buf = array_splice($buffer, $buf_pos); - $new = $this->_reloadBuffer($fp, 100); - if ($new) - { - $buffer = array_merge($buf, $new); - $buf_len = count($buffer); - $buf_pos = 0; - } - else - { - $has_datas = false; - } - } - if ($buf_len - $buf_pos > 0) - { - $size = 0; - for ($i = 0; $i < $startLength && isset($buffer[$buf_pos]); ++$i) - { - ++$size; - $bytes[] = $buffer[$buf_pos++]; - } - $need = $this->_charReader->validateByteSequence( - $bytes, $size); - if ($need > 0) - { - if ($buf_len - $buf_pos < $need) - { - $new = $this->_reloadBuffer($fp, $need); - - if ($new) - { - $buffer = array_merge($buffer, $new); - $buf_len = count($buffer); - } - } - for ($i = 0; $i < $need && isset($buffer[$buf_pos]); ++$i) - { - $bytes[] = $buffer[$buf_pos++]; - } - } - $this->_array[] = $bytes; - ++$this->_array_size; - } - } - while ($has_datas); - - fclose($fp); - } - - /** - * Move the internal pointer to $charOffset in the stream. - * @param int $charOffset - */ - public function setPointer($charOffset) - { - if ($charOffset > $this->_array_size) - { - $charOffset = $this->_array_size; - } - elseif ($charOffset < 0) - { - $charOffset = 0; - } - $this->_offset = $charOffset; - } - - /** - * Empty the stream and reset the internal pointer. - */ - public function flushContents() - { - $this->_offset = 0; - $this->_array = array(); - $this->_array_size = 0; - } - - private function _reloadBuffer($fp, $len) - { - if (!feof($fp) && ($bytes = fread($fp, $len)) !== false) - { - $buf = array(); - for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) - { - $buf[] = self::$_byteMap[$bytes[$i]]; - } - return $buf; - } - return false; - } - - private static function _initializeMaps() - { - if (!isset(self::$_charMap)) - { - self::$_charMap = array(); - for ($byte = 0; $byte < 256; ++$byte) - { - self::$_charMap[$byte] = chr($byte); - } - self::$_byteMap = array_flip(self::$_charMap); - } - } -} diff --git a/h-source/External/swiftmailer/lib/classes/Swift/CharacterStream/NgCharacterStream.php b/h-source/External/swiftmailer/lib/classes/Swift/CharacterStream/NgCharacterStream.php deleted file mode 100755 index f090aa7..0000000 --- a/h-source/External/swiftmailer/lib/classes/Swift/CharacterStream/NgCharacterStream.php +++ /dev/null @@ -1,300 +0,0 @@ -<?php - -/* - CharacterStream implementation using an array in Swift Mailer. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - */ - -//@require 'Swift/CharacterStream.php'; -//@require 'Swift/OutputByteStream.php'; - - -/** - * A CharacterStream implementation which stores characters in an internal array. - * @package Swift - * @subpackage CharacterStream - * @author Xavier De Cock <xdecock@gmail.com> - */ - -Class Swift_CharacterStream_NgCharacterStream - implements Swift_CharacterStream -{ - - /** - * The char reader (lazy-loaded) for the current charset. - * @var Swift_CharacterReader - * @access private - */ - private $_charReader; - - /** - * A factory for creatiing CharacterReader instances. - * @var Swift_CharacterReaderFactory - * @access private - */ - private $_charReaderFactory; - - /** - * The character set this stream is using. - * @var string - * @access private - */ - private $_charset; - - /** - * The datas stored as is - * - * @var string - */ - private $_datas = ""; - - /** - * Number of bytes in the stream - * - * @var int - */ - private $_datasSize = 0; - - /** - * Map - * - * @var mixed - */ - private $_map; - - /** - * Map Type - * - * @var int - */ - private $_mapType = 0; - - /** - * Number of characters in the stream - * - * @var int - */ - private $_charCount = 0; - - /** - * Position in the stream - * - * @var unknown_type - */ - private $_currentPos = 0; - - /** - * The constructor - * - * @param Swift_CharacterReaderFactory $factory - * @param unknown_type $charset - */ - public function __construct(Swift_CharacterReaderFactory $factory, - $charset) - { - $this->setCharacterReaderFactory($factory); - $this->setCharacterSet($charset); - } - - /* -- Changing parameters of the stream -- */ - - /** - * Set the character set used in this CharacterStream. - * @param string $charset - */ - public function setCharacterSet($charset) - { - $this->_charset = $charset; - $this->_charReader = null; - $this->_mapType = 0; - } - - /** - * Set the CharacterReaderFactory for multi charset support. - * @param Swift_CharacterReaderFactory $factory - */ - public function setCharacterReaderFactory( - Swift_CharacterReaderFactory $factory) - { - $this->_charReaderFactory = $factory; - } - - /** - * @see Swift_CharacterStream::flushContents() - * - */ - public function flushContents() - { - $this->_datas = null; - $this->_map = null; - $this->_charCount = 0; - $this->_currentPos = 0; - $this->_datasSize = 0; - } - - /** - * @see Swift_CharacterStream::importByteStream() - * - * @param Swift_OutputByteStream $os - */ - public function importByteStream(Swift_OutputByteStream $os) - { - $this->flushContents(); - $blocks=512; - $os->setReadPointer(0); - while(false!==($read = $os->read($blocks))) - $this->write($read); - } - - /** - * @see Swift_CharacterStream::importString() - * - * @param string $string - */ - public function importString($string) - { - $this->flushContents(); - $this->write($string); - } - - /** - * @see Swift_CharacterStream::read() - * - * @param int $length - * @return string - */ - public function read($length) - { - if ($this->_currentPos>=$this->_charCount) - { - return false; - } - $ret=false; - $length = ($this->_currentPos+$length > $this->_charCount) - ? $this->_charCount - $this->_currentPos - : $length; - switch ($this->_mapType) - { - case Swift_CharacterReader::MAP_TYPE_FIXED_LEN: - $len = $length*$this->_map; - $ret = substr($this->_datas, - $this->_currentPos * $this->_map, - $len); - $this->_currentPos += $length; - break; - - case Swift_CharacterReader::MAP_TYPE_INVALID: - $end = $this->_currentPos + $length; - $end = $end > $this->_charCount - ?$this->_charCount - :$end; - $ret = ''; - for (; $this->_currentPos < $length; ++$this->_currentPos) - { - if (isset ($this->_map[$this->_currentPos])) - { - $ret .= '?'; - } - else - { - $ret .= $this->_datas[$this->_currentPos]; - } - } - break; - - case Swift_CharacterReader::MAP_TYPE_POSITIONS: - $end = $this->_currentPos + $length; - $end = $end > $this->_charCount - ?$this->_charCount - :$end; - $ret = ''; - $start = 0; - if ($this->_currentPos>0) - { - $start = $this->_map['p'][$this->_currentPos-1]; - } - $to = $start; - for (; $this->_currentPos < $end; ++$this->_currentPos) - { - if (isset($this->_map['i'][$this->_currentPos])) { - $ret .= substr($this->_datas, $start, $to - $start).'?'; - $start = $this->_map['p'][$this->_currentPos]; - } else { - $to = $this->_map['p'][$this->_currentPos]; - } - } - $ret .= substr($this->_datas, $start, $to - $start); - break; - } - return $ret; - } - - /** - * @see Swift_CharacterStream::readBytes() - * - * @param int $length - * @return int[] - */ - public function readBytes($length) - { - $read=$this->read($length); - if ($read!==false) - { - $ret = array_map('ord', str_split($read, 1)); - return $ret; - } - return false; - } - - /** - * @see Swift_CharacterStream::setPointer() - * - * @param int $charOffset - */ - public function setPointer($charOffset) - { - if ($this->_charCount<$charOffset){ - $charOffset=$this->_charCount; - } - $this->_currentPos = $charOffset; - } - - /** - * @see Swift_CharacterStream::write() - * - * @param string $chars - */ - public function write($chars) - { - if (!isset($this->_charReader)) - { - $this->_charReader = $this->_charReaderFactory->getReaderFor( - $this->_charset); - $this->_map = array(); - $this->_mapType = $this->_charReader->getMapType(); - } - $ignored=''; - $this->_datas .= $chars; - $this->_charCount += $this->_charReader->getCharPositions(substr($this->_datas, $this->_datasSize), $this->_datasSize, $this->_map, $ignored); - if ($ignored!==false) { - $this->_datasSize=strlen($this->_datas)-strlen($ignored); - } - else - { - $this->_datasSize=strlen($this->_datas); - } - } -}
\ No newline at end of file |