1<?php
2
3/**
4 * UTF8 helper functions
5 *
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
8 *
9 * @author     Andreas Gohr <andi@splitbrain.org>
10 */
11
12use dokuwiki\Utf8\Clean;
13use dokuwiki\Utf8\Conversion;
14use dokuwiki\Utf8\PhpString;
15use dokuwiki\Utf8\Unicode;
16
17/**
18 * check for mb_string support
19 */
20if (!defined('UTF8_MBSTRING')) {
21    if (function_exists('mb_substr') && !defined('UTF8_NOMBSTRING')) {
22        define('UTF8_MBSTRING', 1);
23    } else {
24        define('UTF8_MBSTRING', 0);
25    }
26}
27
28/**
29 * Check if PREG was compiled with UTF-8 support
30 *
31 * Without this many of the functions below will not work, so this is a minimal requirement
32 */
33if (!defined('UTF8_PREGSUPPORT')) {
34    define('UTF8_PREGSUPPORT', (bool)@preg_match('/^.$/u', 'ñ'));
35}
36
37/**
38 * Check if PREG was compiled with Unicode Property support
39 *
40 * This is not required for the functions below, but might be needed in a UTF-8 aware application
41 */
42if (!defined('UTF8_PROPERTYSUPPORT')) {
43    define('UTF8_PROPERTYSUPPORT', (bool)@preg_match('/^\pL$/u', 'ñ'));
44}
45
46
47if (UTF8_MBSTRING) {
48    mb_internal_encoding('UTF-8');
49}
50
51
52if (!function_exists('utf8_isASCII')) {
53    /** @deprecated 2019-06-09 */
54    function utf8_isASCII($str)
55    {
56        dbg_deprecated(Clean::class . '::isASCII()');
57        return Clean::isASCII($str);
58    }
59}
60
61
62if (!function_exists('utf8_strip')) {
63    /** @deprecated 2019-06-09 */
64    function utf8_strip($str)
65    {
66        dbg_deprecated(Clean::class . '::strip()');
67        return Clean::strip($str);
68    }
69}
70
71if (!function_exists('utf8_check')) {
72    /** @deprecated 2019-06-09 */
73    function utf8_check($str)
74    {
75        dbg_deprecated(Clean::class . '::isUtf8()');
76        return Clean::isUtf8($str);
77    }
78}
79
80if (!function_exists('utf8_basename')) {
81    /** @deprecated 2019-06-09 */
82    function utf8_basename($path, $suffix = '')
83    {
84        dbg_deprecated(PhpString::class . '::basename()');
85        return PhpString::basename($path, $suffix);
86    }
87}
88
89if (!function_exists('utf8_strlen')) {
90    /** @deprecated 2019-06-09 */
91    function utf8_strlen($str)
92    {
93        dbg_deprecated(PhpString::class . '::strlen()');
94        return PhpString::strlen($str);
95    }
96}
97
98if (!function_exists('utf8_substr')) {
99    /** @deprecated 2019-06-09 */
100    function utf8_substr($str, $offset, $length = null)
101    {
102        dbg_deprecated(PhpString::class . '::substr()');
103        return PhpString::substr($str, $offset, $length);
104    }
105}
106
107if (!function_exists('utf8_substr_replace')) {
108    /** @deprecated 2019-06-09 */
109    function utf8_substr_replace($string, $replacement, $start, $length = 0)
110    {
111        dbg_deprecated(PhpString::class . '::substr_replace()');
112        return PhpString::substr_replace($string, $replacement, $start, $length);
113    }
114}
115
116if (!function_exists('utf8_ltrim')) {
117    /** @deprecated 2019-06-09 */
118    function utf8_ltrim($str, $charlist = '')
119    {
120        dbg_deprecated(PhpString::class . '::ltrim()');
121        return PhpString::ltrim($str, $charlist);
122    }
123}
124
125if (!function_exists('utf8_rtrim')) {
126    /** @deprecated 2019-06-09 */
127    function utf8_rtrim($str, $charlist = '')
128    {
129        dbg_deprecated(PhpString::class . '::rtrim()');
130        return PhpString::rtrim($str, $charlist);
131    }
132}
133
134if (!function_exists('utf8_trim')) {
135    /** @deprecated 2019-06-09 */
136    function utf8_trim($str, $charlist = '')
137    {
138        dbg_deprecated(PhpString::class . '::trim()');
139        return PhpString::trim($str, $charlist);
140    }
141}
142
143if (!function_exists('utf8_strtolower')) {
144    /** @deprecated 2019-06-09 */
145    function utf8_strtolower($str)
146    {
147        dbg_deprecated(PhpString::class . '::strtolower()');
148        return PhpString::strtolower($str);
149    }
150}
151
152if (!function_exists('utf8_strtoupper')) {
153    /** @deprecated 2019-06-09 */
154    function utf8_strtoupper($str)
155    {
156        dbg_deprecated(PhpString::class . '::strtoupper()');
157        return PhpString::strtoupper($str);
158    }
159}
160
161if (!function_exists('utf8_ucfirst')) {
162    /** @deprecated 2019-06-09 */
163    function utf8_ucfirst($str)
164    {
165        dbg_deprecated(PhpString::class . '::ucfirst()');
166        return PhpString::ucfirst($str);
167    }
168}
169
170if (!function_exists('utf8_ucwords')) {
171    /** @deprecated 2019-06-09 */
172    function utf8_ucwords($str)
173    {
174        dbg_deprecated(PhpString::class . '::ucwords()');
175        return PhpString::ucwords($str);
176    }
177}
178
179if (!function_exists('utf8_deaccent')) {
180    /** @deprecated 2019-06-09 */
181    function utf8_deaccent($str, $case = 0)
182    {
183        dbg_deprecated(Clean::class . '::deaccent()');
184        return Clean::deaccent($str, $case);
185    }
186}
187
188if (!function_exists('utf8_romanize')) {
189    /** @deprecated 2019-06-09 */
190    function utf8_romanize($str)
191    {
192        dbg_deprecated(Clean::class . '::romanize()');
193        return Clean::romanize($str);
194    }
195}
196
197if (!function_exists('utf8_stripspecials')) {
198    /** @deprecated 2019-06-09 */
199    function utf8_stripspecials($str, $repl = '', $additional = '')
200    {
201        dbg_deprecated(Clean::class . '::stripspecials()');
202        return Clean::stripspecials($str, $repl, $additional);
203    }
204}
205
206if (!function_exists('utf8_strpos')) {
207    /** @deprecated 2019-06-09 */
208    function utf8_strpos($haystack, $needle, $offset = 0)
209    {
210        dbg_deprecated(PhpString::class . '::strpos()');
211        return PhpString::strpos($haystack, $needle, $offset);
212    }
213}
214
215if (!function_exists('utf8_tohtml')) {
216    /** @deprecated 2019-06-09 */
217    function utf8_tohtml($str, $all = false)
218    {
219        dbg_deprecated(Conversion::class . '::toHtml()');
220        return Conversion::toHtml($str, $all);
221    }
222}
223
224if (!function_exists('utf8_unhtml')) {
225    /** @deprecated 2019-06-09 */
226    function utf8_unhtml($str, $enties = false)
227    {
228        dbg_deprecated(Conversion::class . '::fromHtml()');
229        return Conversion::fromHtml($str, $enties);
230    }
231}
232
233if (!function_exists('utf8_to_unicode')) {
234    /** @deprecated 2019-06-09 */
235    function utf8_to_unicode($str, $strict = false)
236    {
237        dbg_deprecated(Unicode::class . '::fromUtf8()');
238        return Unicode::fromUtf8($str, $strict);
239    }
240}
241
242if (!function_exists('unicode_to_utf8')) {
243    /** @deprecated 2019-06-09 */
244    function unicode_to_utf8($arr, $strict = false)
245    {
246        dbg_deprecated(Unicode::class . '::toUtf8()');
247        return Unicode::toUtf8($arr, $strict);
248    }
249}
250
251if (!function_exists('utf8_to_utf16be')) {
252    /** @deprecated 2019-06-09 */
253    function utf8_to_utf16be($str, $bom = false)
254    {
255        dbg_deprecated(Conversion::class . '::toUtf16be()');
256        return Conversion::toUtf16be($str, $bom);
257    }
258}
259
260if (!function_exists('utf16be_to_utf8')) {
261    /** @deprecated 2019-06-09 */
262    function utf16be_to_utf8($str)
263    {
264        dbg_deprecated(Conversion::class . '::fromUtf16be()');
265        return Conversion::fromUtf16be($str);
266    }
267}
268
269if (!function_exists('utf8_bad_replace')) {
270    /** @deprecated 2019-06-09 */
271    function utf8_bad_replace($str, $replace = '')
272    {
273        dbg_deprecated(Clean::class . '::replaceBadBytes()');
274        return Clean::replaceBadBytes($str, $replace);
275    }
276}
277
278if (!function_exists('utf8_correctIdx')) {
279    /** @deprecated 2019-06-09 */
280    function utf8_correctIdx($str, $i, $next = false)
281    {
282        dbg_deprecated(Clean::class . '::correctIdx()');
283        return Clean::correctIdx($str, $i, $next);
284    }
285}
286