Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
/**
4
 * This file is part of FPDI
5
 *
6
 * @package   setasign\Fpdi
7
 * @copyright Copyright (c) 2023 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\Type;
12
 
13
use setasign\Fpdi\PdfParser\StreamReader;
14
 
15
/**
16
 * Class representing a hexadecimal encoded PDF string object
17
 */
18
class PdfHexString extends PdfType
19
{
20
    /**
21
     * Parses a hexadecimal string object from the stream reader.
22
     *
23
     * @param StreamReader $streamReader
24
     * @return false|self
25
     */
26
    public static function parse(StreamReader $streamReader)
27
    {
28
        $bufferOffset = $streamReader->getOffset();
29
 
30
        while (true) {
31
            $buffer = $streamReader->getBuffer(false);
32
            $pos = \strpos($buffer, '>', $bufferOffset);
33
            if ($pos === false) {
34
                if (!$streamReader->increaseLength()) {
35
                    return false;
36
                }
37
                continue;
38
            }
39
 
40
            break;
41
        }
42
 
43
        $result = \substr($buffer, $bufferOffset, $pos - $bufferOffset);
44
        $streamReader->setOffset($pos + 1);
45
 
46
        $v = new self();
47
        $v->value = $result;
48
 
49
        return $v;
50
    }
51
 
52
    /**
53
     * Helper method to create an instance.
54
     *
55
     * @param string $string The hex encoded string.
56
     * @return self
57
     */
58
    public static function create($string)
59
    {
60
        $v = new self();
61
        $v->value = $string;
62
 
63
        return $v;
64
    }
65
 
66
    /**
67
     * Ensures that the passed value is a PdfHexString instance.
68
     *
69
     * @param mixed $hexString
70
     * @return self
71
     * @throws PdfTypeException
72
     */
73
    public static function ensure($hexString)
74
    {
75
        return PdfType::ensureType(self::class, $hexString, 'Hex string value expected.');
76
    }
77
}