composer package updates
[openemr.git] / vendor / symfony / polyfill-ctype / Ctype.php
blob58414dc73bd45b931b73a05a040d9ca23a61acf6
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Polyfill\Ctype;
14 /**
15 * Ctype implementation through regex.
17 * @internal
19 * @author Gert de Pagter <BackEndTea@gmail.com>
21 final class Ctype
23 /**
24 * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise.
26 * @see https://php.net/ctype-alnum
28 * @param string|int $text
30 * @return bool
32 public static function ctype_alnum($text)
34 $text = self::convert_int_to_char_for_ctype($text);
36 return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
39 /**
40 * Returns TRUE if every character in text is a letter, FALSE otherwise.
42 * @see https://php.net/ctype-alpha
44 * @param string|int $text
46 * @return bool
48 public static function ctype_alpha($text)
50 $text = self::convert_int_to_char_for_ctype($text);
52 return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text);
55 /**
56 * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise.
58 * @see https://php.net/ctype-cntrl
60 * @param string|int $text
62 * @return bool
64 public static function ctype_cntrl($text)
66 $text = self::convert_int_to_char_for_ctype($text);
68 return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text);
71 /**
72 * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
74 * @see https://php.net/ctype-digit
76 * @param string|int $text
78 * @return bool
80 public static function ctype_digit($text)
82 $text = self::convert_int_to_char_for_ctype($text);
84 return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text);
87 /**
88 * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise.
90 * @see https://php.net/ctype-graph
92 * @param string|int $text
94 * @return bool
96 public static function ctype_graph($text)
98 $text = self::convert_int_to_char_for_ctype($text);
100 return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text);
104 * Returns TRUE if every character in text is a lowercase letter.
106 * @see https://php.net/ctype-lower
108 * @param string|int $text
110 * @return bool
112 public static function ctype_lower($text)
114 $text = self::convert_int_to_char_for_ctype($text);
116 return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
120 * Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all.
122 * @see https://php.net/ctype-print
124 * @param string|int $text
126 * @return bool
128 public static function ctype_print($text)
130 $text = self::convert_int_to_char_for_ctype($text);
132 return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text);
136 * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise.
138 * @see https://php.net/ctype-punct
140 * @param string|int $text
142 * @return bool
144 public static function ctype_punct($text)
146 $text = self::convert_int_to_char_for_ctype($text);
148 return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text);
152 * Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.
154 * @see https://php.net/ctype-space
156 * @param string|int $text
158 * @return bool
160 public static function ctype_space($text)
162 $text = self::convert_int_to_char_for_ctype($text);
164 return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text);
168 * Returns TRUE if every character in text is an uppercase letter.
170 * @see https://php.net/ctype-upper
172 * @param string|int $text
174 * @return bool
176 public static function ctype_upper($text)
178 $text = self::convert_int_to_char_for_ctype($text);
180 return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text);
184 * Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise.
186 * @see https://php.net/ctype-xdigit
188 * @param string|int $text
190 * @return bool
192 public static function ctype_xdigit($text)
194 $text = self::convert_int_to_char_for_ctype($text);
196 return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text);
200 * Converts integers to their char versions according to normal ctype behaviour, if needed.
202 * If an integer between -128 and 255 inclusive is provided,
203 * it is interpreted as the ASCII value of a single character
204 * (negative values have 256 added in order to allow characters in the Extended ASCII range).
205 * Any other integer is interpreted as a string containing the decimal digits of the integer.
207 * @param string|int $int
209 * @return mixed
211 private static function convert_int_to_char_for_ctype($int)
213 if (!\is_int($int)) {
214 return $int;
217 if ($int < -128 || $int > 255) {
218 return (string) $int;
221 if ($int < 0) {
222 $int += 256;
225 return \chr($int);