Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 39 and 311]

   1  <?php
   2  
   3  /**
   4   * This file is part of FPDI
   5   *
   6   * @package   setasign\Fpdi
   7   * @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
   8   * @license   http://opensource.org/licenses/mit-license The MIT License
   9   */
  10  
  11  namespace setasign\Fpdi\PdfParser\Filter;
  12  
  13  /**
  14   * Class for handling ASCII hexadecimal encoded data
  15   */
  16  class AsciiHex implements FilterInterface
  17  {
  18      /**
  19       * Converts an ASCII hexadecimal encoded string into its binary representation.
  20       *
  21       * @param string $data The input string
  22       * @return string
  23       */
  24      public function decode($data)
  25      {
  26          $data = \preg_replace('/[^0-9A-Fa-f]/', '', \rtrim($data, '>'));
  27          if ((\strlen($data) % 2) === 1) {
  28              $data .= '0';
  29          }
  30  
  31          return \pack('H*', $data);
  32      }
  33  
  34      /**
  35       * Converts a string into ASCII hexadecimal representation.
  36       *
  37       * @param string $data The input string
  38       * @param boolean $leaveEOD
  39       * @return string
  40       */
  41      public function encode($data, $leaveEOD = false)
  42      {
  43          $t = \unpack('H*', $data);
  44          return \current($t)
  45              . ($leaveEOD ? '' : '>');
  46      }
  47  }