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