Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / lsolesen / pel / src / PelEntryAscii.php
1 <?php
2
3 /**
4  * PEL: PHP Exif Library.
5  * A library with support for reading and
6  * writing all Exif headers in JPEG and TIFF images using PHP.
7  *
8  * Copyright (C) 2004, 2005, 2006, 2007 Martin Geisler.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program in the file COPYING; if not, write to the
22  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23  * Boston, MA 02110-1301 USA
24  */
25 namespace lsolesen\pel;
26
27 /**
28  * Classes used to hold ASCII strings.
29  *
30  * The classes defined here are to be used for Exif entries holding
31  * ASCII strings, such as {@link PelTag::MAKE}, {@link
32  * PelTag::SOFTWARE}, and {@link PelTag::DATE_TIME}. For
33  * entries holding normal textual ASCII strings the class {@link
34  * PelEntryAscii} should be used, but for entries holding
35  * timestamps the class {@link PelEntryTime} would be more
36  * convenient instead. Copyright information is handled by the {@link
37  * PelEntryCopyright} class.
38  *
39  * @author Martin Geisler <mgeisler@users.sourceforge.net>
40  * @license http://www.gnu.org/licenses/gpl.html GNU General Public
41  *          License (GPL)
42  * @package PEL
43  */
44
45 /**
46  * Class for holding a plain ASCII string.
47  *
48  * This class can hold a single ASCII string, and it will be used as in
49  * <code>
50  * $entry = $ifd->getEntry(PelTag::IMAGE_DESCRIPTION);
51  * print($entry->getValue());
52  * $entry->setValue('This is my image. I like it.');
53  * </code>
54  *
55  * @author Martin Geisler <mgeisler@users.sourceforge.net>
56  * @package PEL
57  */
58 class PelEntryAscii extends PelEntry
59 {
60
61     /**
62      * The string hold by this entry.
63      *
64      * This is the string that was given to the {@link __construct
65      * constructor} or later to {@link setValue}, without any final NULL
66      * character.
67      *
68      * @var string
69      */
70     private $str;
71
72     /**
73      * Make a new PelEntry that can hold an ASCII string.
74      *
75      * @param int $tag
76      *            the tag which this entry represents. This should be
77      *            one of the constants defined in {@link PelTag}, e.g., {@link
78      *            PelTag::IMAGE_DESCRIPTION}, {@link PelTag::MODEL}, or any other
79      *            tag with format {@link PelFormat::ASCII}.
80      *
81      * @param string $str
82      *            the string that this entry will represent. The
83      *            string must obey the same rules as the string argument to {@link
84      *            setValue}, namely that it should be given without any trailing
85      *            NULL character and that it must be plain 7-bit ASCII.
86      */
87     public function __construct($tag, $str = '')
88     {
89         $this->tag = $tag;
90         $this->format = PelFormat::ASCII;
91         self::setValue($str);
92     }
93
94     /**
95      * Give the entry a new ASCII value.
96      *
97      * This will overwrite the previous value. The value can be
98      * retrieved later with the {@link getValue} method.
99      *
100      * @param
101      *            string the new value of the entry. This should be given
102      *            without any trailing NULL character. The string must be plain
103      *            7-bit ASCII, the string should contain no high bytes.
104      *
105      * @todo Implement check for high bytes?
106      */
107     public function setValue($str)
108     {
109         $this->components = strlen($str) + 1;
110         $this->str = $str;
111         $this->bytes = $str . chr(0x00);
112     }
113
114     /**
115      * Return the ASCII string of the entry.
116      *
117      * @return string the string held, without any final NULL character.
118      *         The string will be the same as the one given to {@link setValue}
119      *         or to the {@link __construct constructor}.
120      */
121     public function getValue()
122     {
123         return $this->str;
124     }
125
126     /**
127      * Return the ASCII string of the entry.
128      *
129      * This methods returns the same as {@link getValue}.
130      *
131      * @param
132      *            boolean not used with ASCII entries.
133      *
134      * @return string the string held, without any final NULL character.
135      *         The string will be the same as the one given to {@link setValue}
136      *         or to the {@link __construct constructor}.
137      */
138     public function getText($brief = false)
139     {
140         return $this->str;
141     }
142 }