Fix various errors in PHPUnit tests on PHP 8
[dokuwiki.git] / inc / utf8.php
blob1227407bf55a9746e028ddb59f01f39a67e06976
1 <?php
2 /**
3 * UTF8 helper functions
5 * This file now only intitializes the UTF-8 capability detection and defines helper
6 * functions if needed. All actual code is in the \dokuwiki\Utf8 classes
8 * @author Andreas Gohr <andi@splitbrain.org>
9 */
11 use dokuwiki\Utf8\Clean;
12 use dokuwiki\Utf8\Conversion;
13 use dokuwiki\Utf8\PhpString;
14 use dokuwiki\Utf8\Unicode;
16 /**
17 * check for mb_string support
19 if (!defined('UTF8_MBSTRING')) {
20 if (function_exists('mb_substr') && !defined('UTF8_NOMBSTRING')) {
21 define('UTF8_MBSTRING', 1);
22 } else {
23 define('UTF8_MBSTRING', 0);
27 /**
28 * Check if PREG was compiled with UTF-8 support
30 * Without this many of the functions below will not work, so this is a minimal requirement
32 if (!defined('UTF8_PREGSUPPORT')) {
33 define('UTF8_PREGSUPPORT', (bool)@preg_match('/^.$/u', 'ñ'));
36 /**
37 * Check if PREG was compiled with Unicode Property support
39 * This is not required for the functions below, but might be needed in a UTF-8 aware application
41 if (!defined('UTF8_PROPERTYSUPPORT')) {
42 define('UTF8_PROPERTYSUPPORT', (bool)@preg_match('/^\pL$/u', 'ñ'));
46 if (UTF8_MBSTRING) {
47 mb_internal_encoding('UTF-8');
51 if (!function_exists('utf8_isASCII')) {
52 /** @deprecated 2019-06-09 */
53 function utf8_isASCII($str)
55 dbg_deprecated(Clean::class . '::isASCII()');
56 return Clean::isASCII($str);
61 if (!function_exists('utf8_strip')) {
62 /** @deprecated 2019-06-09 */
63 function utf8_strip($str)
65 dbg_deprecated(Clean::class . '::strip()');
66 return Clean::strip($str);
70 if (!function_exists('utf8_check')) {
71 /** @deprecated 2019-06-09 */
72 function utf8_check($str)
74 dbg_deprecated(Clean::class . '::isUtf8()');
75 return Clean::isUtf8($str);
79 if (!function_exists('utf8_basename')) {
80 /** @deprecated 2019-06-09 */
81 function utf8_basename($path, $suffix = '')
83 dbg_deprecated(PhpString::class . '::basename()');
84 return PhpString::basename($path, $suffix);
88 if (!function_exists('utf8_strlen')) {
89 /** @deprecated 2019-06-09 */
90 function utf8_strlen($str)
92 dbg_deprecated(PhpString::class . '::strlen()');
93 return PhpString::strlen($str);
97 if (!function_exists('utf8_substr')) {
98 /** @deprecated 2019-06-09 */
99 function utf8_substr($str, $offset, $length = null)
101 dbg_deprecated(PhpString::class . '::substr()');
102 return PhpString::substr($str, $offset, $length);
106 if (!function_exists('utf8_substr_replace')) {
107 /** @deprecated 2019-06-09 */
108 function utf8_substr_replace($string, $replacement, $start, $length = 0)
110 dbg_deprecated(PhpString::class . '::substr_replace()');
111 return PhpString::substr_replace($string, $replacement, $start, $length);
115 if (!function_exists('utf8_ltrim')) {
116 /** @deprecated 2019-06-09 */
117 function utf8_ltrim($str, $charlist = '')
119 dbg_deprecated(PhpString::class . '::ltrim()');
120 return PhpString::ltrim($str, $charlist);
124 if (!function_exists('utf8_rtrim')) {
125 /** @deprecated 2019-06-09 */
126 function utf8_rtrim($str, $charlist = '')
128 dbg_deprecated(PhpString::class . '::rtrim()');
129 return PhpString::rtrim($str, $charlist);
133 if (!function_exists('utf8_trim')) {
134 /** @deprecated 2019-06-09 */
135 function utf8_trim($str, $charlist = '')
137 dbg_deprecated(PhpString::class . '::trim()');
138 return PhpString::trim($str, $charlist);
142 if (!function_exists('utf8_strtolower')) {
143 /** @deprecated 2019-06-09 */
144 function utf8_strtolower($str)
146 dbg_deprecated(PhpString::class . '::strtolower()');
147 return PhpString::strtolower($str);
151 if (!function_exists('utf8_strtoupper')) {
152 /** @deprecated 2019-06-09 */
153 function utf8_strtoupper($str)
155 dbg_deprecated(PhpString::class . '::strtoupper()');
156 return PhpString::strtoupper($str);
160 if (!function_exists('utf8_ucfirst')) {
161 /** @deprecated 2019-06-09 */
162 function utf8_ucfirst($str)
164 dbg_deprecated(PhpString::class . '::ucfirst()');
165 return PhpString::ucfirst($str);
169 if (!function_exists('utf8_ucwords')) {
170 /** @deprecated 2019-06-09 */
171 function utf8_ucwords($str)
173 dbg_deprecated(PhpString::class . '::ucwords()');
174 return PhpString::ucwords($str);
178 if (!function_exists('utf8_deaccent')) {
179 /** @deprecated 2019-06-09 */
180 function utf8_deaccent($str, $case = 0)
182 dbg_deprecated(Clean::class . '::deaccent()');
183 return Clean::deaccent($str, $case);
187 if (!function_exists('utf8_romanize')) {
188 /** @deprecated 2019-06-09 */
189 function utf8_romanize($str)
191 dbg_deprecated(Clean::class . '::romanize()');
192 return Clean::romanize($str);
196 if (!function_exists('utf8_stripspecials')) {
197 /** @deprecated 2019-06-09 */
198 function utf8_stripspecials($str, $repl = '', $additional = '')
200 dbg_deprecated(Clean::class . '::stripspecials()');
201 return Clean::stripspecials($str, $repl, $additional);
205 if (!function_exists('utf8_strpos')) {
206 /** @deprecated 2019-06-09 */
207 function utf8_strpos($haystack, $needle, $offset = 0)
209 dbg_deprecated(PhpString::class . '::strpos()');
210 return PhpString::strpos($haystack, $needle, $offset);
214 if (!function_exists('utf8_tohtml')) {
215 /** @deprecated 2019-06-09 */
216 function utf8_tohtml($str, $all = false)
218 dbg_deprecated(Conversion::class . '::toHtml()');
219 return Conversion::toHtml($str, $all);
223 if (!function_exists('utf8_unhtml')) {
224 /** @deprecated 2019-06-09 */
225 function utf8_unhtml($str, $enties = false)
227 dbg_deprecated(Conversion::class . '::fromHtml()');
228 return Conversion::fromHtml($str, $enties);
232 if (!function_exists('utf8_to_unicode')) {
233 /** @deprecated 2019-06-09 */
234 function utf8_to_unicode($str, $strict = false)
236 dbg_deprecated(Unicode::class . '::fromUtf8()');
237 return Unicode::fromUtf8($str, $strict);
241 if (!function_exists('unicode_to_utf8')) {
242 /** @deprecated 2019-06-09 */
243 function unicode_to_utf8($arr, $strict = false)
245 dbg_deprecated(Unicode::class . '::toUtf8()');
246 return Unicode::toUtf8($arr, $strict);
250 if (!function_exists('utf8_to_utf16be')) {
251 /** @deprecated 2019-06-09 */
252 function utf8_to_utf16be($str, $bom = false)
254 dbg_deprecated(Conversion::class . '::toUtf16be()');
255 return Conversion::toUtf16be($str, $bom);
259 if (!function_exists('utf16be_to_utf8')) {
260 /** @deprecated 2019-06-09 */
261 function utf16be_to_utf8($str)
263 dbg_deprecated(Conversion::class . '::fromUtf16be()');
264 return Conversion::fromUtf16be($str);
268 if (!function_exists('utf8_bad_replace')) {
269 /** @deprecated 2019-06-09 */
270 function utf8_bad_replace($str, $replace = '')
272 dbg_deprecated(Clean::class . '::replaceBadBytes()');
273 return Clean::replaceBadBytes($str, $replace);
277 if (!function_exists('utf8_correctIdx')) {
278 /** @deprecated 2019-06-09 */
279 function utf8_correctIdx($str, $i, $next = false)
281 dbg_deprecated(Clean::class . '::correctIdx()');
282 return Clean::correctIdx($str, $i, $next);