update tests to match new is_ssl behaviour
[dokuwiki.git] / inc / utf8.php
blob5ac3cd6a19c29398efe22a78c4c96cc17dbc1e50
1 <?php
3 /**
4 * UTF8 helper functions
6 * This file now only intitializes the UTF-8 capability detection and defines helper
7 * functions if needed. All actual code is in the \dokuwiki\Utf8 classes
9 * @author Andreas Gohr <andi@splitbrain.org>
12 use dokuwiki\Utf8\Clean;
13 use dokuwiki\Utf8\Conversion;
14 use dokuwiki\Utf8\PhpString;
15 use dokuwiki\Utf8\Unicode;
17 /**
18 * check for mb_string support
20 if (!defined('UTF8_MBSTRING')) {
21 if (function_exists('mb_substr') && !defined('UTF8_NOMBSTRING')) {
22 define('UTF8_MBSTRING', 1);
23 } else {
24 define('UTF8_MBSTRING', 0);
28 /**
29 * Check if PREG was compiled with UTF-8 support
31 * Without this many of the functions below will not work, so this is a minimal requirement
33 if (!defined('UTF8_PREGSUPPORT')) {
34 define('UTF8_PREGSUPPORT', (bool)@preg_match('/^.$/u', 'ñ'));
37 /**
38 * Check if PREG was compiled with Unicode Property support
40 * This is not required for the functions below, but might be needed in a UTF-8 aware application
42 if (!defined('UTF8_PROPERTYSUPPORT')) {
43 define('UTF8_PROPERTYSUPPORT', (bool)@preg_match('/^\pL$/u', 'ñ'));
47 if (UTF8_MBSTRING) {
48 mb_internal_encoding('UTF-8');
52 if (!function_exists('utf8_isASCII')) {
53 /** @deprecated 2019-06-09 */
54 function utf8_isASCII($str)
56 dbg_deprecated(Clean::class . '::isASCII()');
57 return Clean::isASCII($str);
62 if (!function_exists('utf8_strip')) {
63 /** @deprecated 2019-06-09 */
64 function utf8_strip($str)
66 dbg_deprecated(Clean::class . '::strip()');
67 return Clean::strip($str);
71 if (!function_exists('utf8_check')) {
72 /** @deprecated 2019-06-09 */
73 function utf8_check($str)
75 dbg_deprecated(Clean::class . '::isUtf8()');
76 return Clean::isUtf8($str);
80 if (!function_exists('utf8_basename')) {
81 /** @deprecated 2019-06-09 */
82 function utf8_basename($path, $suffix = '')
84 dbg_deprecated(PhpString::class . '::basename()');
85 return PhpString::basename($path, $suffix);
89 if (!function_exists('utf8_strlen')) {
90 /** @deprecated 2019-06-09 */
91 function utf8_strlen($str)
93 dbg_deprecated(PhpString::class . '::strlen()');
94 return PhpString::strlen($str);
98 if (!function_exists('utf8_substr')) {
99 /** @deprecated 2019-06-09 */
100 function utf8_substr($str, $offset, $length = null)
102 dbg_deprecated(PhpString::class . '::substr()');
103 return PhpString::substr($str, $offset, $length);
107 if (!function_exists('utf8_substr_replace')) {
108 /** @deprecated 2019-06-09 */
109 function utf8_substr_replace($string, $replacement, $start, $length = 0)
111 dbg_deprecated(PhpString::class . '::substr_replace()');
112 return PhpString::substr_replace($string, $replacement, $start, $length);
116 if (!function_exists('utf8_ltrim')) {
117 /** @deprecated 2019-06-09 */
118 function utf8_ltrim($str, $charlist = '')
120 dbg_deprecated(PhpString::class . '::ltrim()');
121 return PhpString::ltrim($str, $charlist);
125 if (!function_exists('utf8_rtrim')) {
126 /** @deprecated 2019-06-09 */
127 function utf8_rtrim($str, $charlist = '')
129 dbg_deprecated(PhpString::class . '::rtrim()');
130 return PhpString::rtrim($str, $charlist);
134 if (!function_exists('utf8_trim')) {
135 /** @deprecated 2019-06-09 */
136 function utf8_trim($str, $charlist = '')
138 dbg_deprecated(PhpString::class . '::trim()');
139 return PhpString::trim($str, $charlist);
143 if (!function_exists('utf8_strtolower')) {
144 /** @deprecated 2019-06-09 */
145 function utf8_strtolower($str)
147 dbg_deprecated(PhpString::class . '::strtolower()');
148 return PhpString::strtolower($str);
152 if (!function_exists('utf8_strtoupper')) {
153 /** @deprecated 2019-06-09 */
154 function utf8_strtoupper($str)
156 dbg_deprecated(PhpString::class . '::strtoupper()');
157 return PhpString::strtoupper($str);
161 if (!function_exists('utf8_ucfirst')) {
162 /** @deprecated 2019-06-09 */
163 function utf8_ucfirst($str)
165 dbg_deprecated(PhpString::class . '::ucfirst()');
166 return PhpString::ucfirst($str);
170 if (!function_exists('utf8_ucwords')) {
171 /** @deprecated 2019-06-09 */
172 function utf8_ucwords($str)
174 dbg_deprecated(PhpString::class . '::ucwords()');
175 return PhpString::ucwords($str);
179 if (!function_exists('utf8_deaccent')) {
180 /** @deprecated 2019-06-09 */
181 function utf8_deaccent($str, $case = 0)
183 dbg_deprecated(Clean::class . '::deaccent()');
184 return Clean::deaccent($str, $case);
188 if (!function_exists('utf8_romanize')) {
189 /** @deprecated 2019-06-09 */
190 function utf8_romanize($str)
192 dbg_deprecated(Clean::class . '::romanize()');
193 return Clean::romanize($str);
197 if (!function_exists('utf8_stripspecials')) {
198 /** @deprecated 2019-06-09 */
199 function utf8_stripspecials($str, $repl = '', $additional = '')
201 dbg_deprecated(Clean::class . '::stripspecials()');
202 return Clean::stripspecials($str, $repl, $additional);
206 if (!function_exists('utf8_strpos')) {
207 /** @deprecated 2019-06-09 */
208 function utf8_strpos($haystack, $needle, $offset = 0)
210 dbg_deprecated(PhpString::class . '::strpos()');
211 return PhpString::strpos($haystack, $needle, $offset);
215 if (!function_exists('utf8_tohtml')) {
216 /** @deprecated 2019-06-09 */
217 function utf8_tohtml($str, $all = false)
219 dbg_deprecated(Conversion::class . '::toHtml()');
220 return Conversion::toHtml($str, $all);
224 if (!function_exists('utf8_unhtml')) {
225 /** @deprecated 2019-06-09 */
226 function utf8_unhtml($str, $enties = false)
228 dbg_deprecated(Conversion::class . '::fromHtml()');
229 return Conversion::fromHtml($str, $enties);
233 if (!function_exists('utf8_to_unicode')) {
234 /** @deprecated 2019-06-09 */
235 function utf8_to_unicode($str, $strict = false)
237 dbg_deprecated(Unicode::class . '::fromUtf8()');
238 return Unicode::fromUtf8($str, $strict);
242 if (!function_exists('unicode_to_utf8')) {
243 /** @deprecated 2019-06-09 */
244 function unicode_to_utf8($arr, $strict = false)
246 dbg_deprecated(Unicode::class . '::toUtf8()');
247 return Unicode::toUtf8($arr, $strict);
251 if (!function_exists('utf8_to_utf16be')) {
252 /** @deprecated 2019-06-09 */
253 function utf8_to_utf16be($str, $bom = false)
255 dbg_deprecated(Conversion::class . '::toUtf16be()');
256 return Conversion::toUtf16be($str, $bom);
260 if (!function_exists('utf16be_to_utf8')) {
261 /** @deprecated 2019-06-09 */
262 function utf16be_to_utf8($str)
264 dbg_deprecated(Conversion::class . '::fromUtf16be()');
265 return Conversion::fromUtf16be($str);
269 if (!function_exists('utf8_bad_replace')) {
270 /** @deprecated 2019-06-09 */
271 function utf8_bad_replace($str, $replace = '')
273 dbg_deprecated(Clean::class . '::replaceBadBytes()');
274 return Clean::replaceBadBytes($str, $replace);
278 if (!function_exists('utf8_correctIdx')) {
279 /** @deprecated 2019-06-09 */
280 function utf8_correctIdx($str, $i, $next = false)
282 dbg_deprecated(Clean::class . '::correctIdx()');
283 return Clean::correctIdx($str, $i, $next);