root / drupal7 / sites / all / libraries / fpdi-1.5.4 / filters / FilterASCIIHexDecode.php @ 7295e063
1 | 60370e04 | Assos Assos | <?php
|
---|---|---|---|
2 | //
|
||
3 | // FPDI - Version 1.5.4
|
||
4 | //
|
||
5 | // Copyright 2004-2015 Setasign - Jan Slabon
|
||
6 | //
|
||
7 | // Licensed under the Apache License, Version 2.0 (the "License");
|
||
8 | // you may not use this file except in compliance with the License.
|
||
9 | // You may obtain a copy of the License at
|
||
10 | //
|
||
11 | // http://www.apache.org/licenses/LICENSE-2.0
|
||
12 | //
|
||
13 | // Unless required by applicable law or agreed to in writing, software
|
||
14 | // distributed under the License is distributed on an "AS IS" BASIS,
|
||
15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
16 | // See the License for the specific language governing permissions and
|
||
17 | // limitations under the License.
|
||
18 | //
|
||
19 | |||
20 | /**
|
||
21 | * Class FilterASCIIHexDecode
|
||
22 | */
|
||
23 | class FilterASCIIHexDecode |
||
24 | { |
||
25 | /**
|
||
26 | * Converts an ASCII hexadecimal encoded string into it's binary representation.
|
||
27 | *
|
||
28 | * @param string $data The input string
|
||
29 | * @return string
|
||
30 | */
|
||
31 | public function decode($data) |
||
32 | { |
||
33 | $data = preg_replace('/[^0-9A-Fa-f]/', '', rtrim($data, '>')); |
||
34 | if ((strlen($data) % 2) == 1) { |
||
35 | $data .= '0'; |
||
36 | } |
||
37 | |||
38 | return pack('H*', $data); |
||
39 | } |
||
40 | |||
41 | /**
|
||
42 | * Converts a string into ASCII hexadecimal representation.
|
||
43 | *
|
||
44 | * @param string $data The input string
|
||
45 | * @param boolean $leaveEOD
|
||
46 | * @return string
|
||
47 | */
|
||
48 | public function encode($data, $leaveEOD = false) |
||
49 | { |
||
50 | return current(unpack('H*', $data)) . ($leaveEOD ? '' : '>'); |
||
51 | } |
||
52 | } |