Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AsciiHex.php
Go to the documentation of this file.
1 <?php
24 #require_once 'Zend/Pdf/Filter/Interface.php';
25 
34 {
43  public static function encode($data, $params = null)
44  {
45  return bin2hex($data) . '>';
46  }
47 
56  public static function decode($data, $params = null)
57  {
58  $output = '';
59  $oddCode = true;
60  $commentMode = false;
61 
62  for ($count = 0; $count < strlen($data) && $data[$count] != '>'; $count++) {
63  $charCode = ord($data[$count]);
64 
65  if ($commentMode) {
66  if ($charCode == 0x0A || $charCode == 0x0D ) {
67  $commentMode = false;
68  }
69 
70  continue;
71  }
72 
73  switch ($charCode) {
74  //Skip white space
75  case 0x00: // null character
76  // fall through to next case
77  case 0x09: // Tab
78  // fall through to next case
79  case 0x0A: // Line feed
80  // fall through to next case
81  case 0x0C: // Form Feed
82  // fall through to next case
83  case 0x0D: // Carriage return
84  // fall through to next case
85  case 0x20: // Space
86  // Do nothing
87  break;
88 
89  case 0x25: // '%'
90  // Switch to comment mode
91  $commentMode = true;
92  break;
93 
94  default:
95  if ($charCode >= 0x30 /*'0'*/ && $charCode <= 0x39 /*'9'*/) {
96  $code = $charCode - 0x30;
97  } else if ($charCode >= 0x41 /*'A'*/ && $charCode <= 0x46 /*'F'*/) {
98  $code = $charCode - 0x37/*0x41 - 0x0A*/;
99  } else if ($charCode >= 0x61 /*'a'*/ && $charCode <= 0x66 /*'f'*/) {
100  $code = $charCode - 0x57/*0x61 - 0x0A*/;
101  } else {
102  #require_once 'Zend/Pdf/Exception.php';
103  throw new Zend_Pdf_Exception('Wrong character in a encoded stream');
104  }
105 
106  if ($oddCode) {
107  // Odd pass. Store hex digit for next pass
108  // Scope of $hexCodeHigh variable is whole function
109  $hexCodeHigh = $code;
110  } else {
111  // Even pass.
112  // Add decoded character to the output
113  // ($hexCodeHigh is stored in previous pass)
114  $output .= chr($hexCodeHigh*16 + $code);
115  }
116  $oddCode = !$oddCode;
117 
118  break;
119  }
120  }
121 
122  /* Check that stream is terminated by End Of Data marker */
123  if ($data[$count] != '>') {
124  #require_once 'Zend/Pdf/Exception.php';
125  throw new Zend_Pdf_Exception('Wrong encoded stream End Of Data marker.');
126  }
127 
128  /* Last '0' character is omitted */
129  if (!$oddCode) {
130  $output .= chr($hexCodeHigh*16);
131  }
132 
133  return $output;
134  }
135 }
$count
Definition: recent.phtml:13
static decode($data, $params=null)
Definition: AsciiHex.php:56
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
static encode($data, $params=null)
Definition: AsciiHex.php:43
$code
Definition: info.phtml:12