forked from mreg-archive/fpdi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilterASCIIHexDecode.php
34 lines (32 loc) · 974 Bytes
/
FilterASCIIHexDecode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
* This file is part of FPDI
*
* @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1
*/
/**
* PLEASE NOTE THAT THIS FILE IS PROCESSED PROGRAMMATICALLY FOR THE itbz\fpdi
* RELEASE BUG REPORTS AND SUGGESTED CHANGES SHOULD BE DIRECTED TO SETASIGN
* DIRECTLY BUGS RELATED TO THIS CONVERSION CAN BE REPORTED AT
* https://github.com/hanneskod/fpdi/issues
*/
namespace fpdi {
class FilterASCIIHexDecode
{
public function decode($data)
{
$data = preg_replace('/[^0-9A-Fa-f]/', '', rtrim($data, '>'));
if (strlen($data) % 2 == 1) {
$data .= '0';
}
return pack('H*', $data);
}
public function encode($data, $leaveEOD = false)
{
return current(unpack('H*', $data)) . ($leaveEOD ? '' : '>');
}
}
}