summaryrefslogtreecommitdiff
path: root/platform/www/inc/utf8.php
blob: 1227407bf55a9746e028ddb59f01f39a67e06976 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/**
 * UTF8 helper functions
 *
 * This file now only intitializes the UTF-8 capability detection and defines helper
 * functions if needed. All actual code is in the \dokuwiki\Utf8 classes
 *
 * @author     Andreas Gohr <andi@splitbrain.org>
 */

use dokuwiki\Utf8\Clean;
use dokuwiki\Utf8\Conversion;
use dokuwiki\Utf8\PhpString;
use dokuwiki\Utf8\Unicode;

/**
 * check for mb_string support
 */
if (!defined('UTF8_MBSTRING')) {
    if (function_exists('mb_substr') && !defined('UTF8_NOMBSTRING')) {
        define('UTF8_MBSTRING', 1);
    } else {
        define('UTF8_MBSTRING', 0);
    }
}

/**
 * Check if PREG was compiled with UTF-8 support
 *
 * Without this many of the functions below will not work, so this is a minimal requirement
 */
if (!defined('UTF8_PREGSUPPORT')) {
    define('UTF8_PREGSUPPORT', (bool)@preg_match('/^.$/u', 'ñ'));
}

/**
 * Check if PREG was compiled with Unicode Property support
 *
 * This is not required for the functions below, but might be needed in a UTF-8 aware application
 */
if (!defined('UTF8_PROPERTYSUPPORT')) {
    define('UTF8_PROPERTYSUPPORT', (bool)@preg_match('/^\pL$/u', 'ñ'));
}


if (UTF8_MBSTRING) {
    mb_internal_encoding('UTF-8');
}


if (!function_exists('utf8_isASCII')) {
    /** @deprecated 2019-06-09 */
    function utf8_isASCII($str)
    {
        dbg_deprecated(Clean::class . '::isASCII()');
        return Clean::isASCII($str);
    }
}


if (!function_exists('utf8_strip')) {
    /** @deprecated 2019-06-09 */
    function utf8_strip($str)
    {
        dbg_deprecated(Clean::class . '::strip()');
        return Clean::strip($str);
    }
}

if (!function_exists('utf8_check')) {
    /** @deprecated 2019-06-09 */
    function utf8_check($str)
    {
        dbg_deprecated(Clean::class . '::isUtf8()');
        return Clean::isUtf8($str);
    }
}

if (!function_exists('utf8_basename')) {
    /** @deprecated 2019-06-09 */
    function utf8_basename($path, $suffix = '')
    {
        dbg_deprecated(PhpString::class . '::basename()');
        return PhpString::basename($path, $suffix);
    }
}

if (!function_exists('utf8_strlen')) {
    /** @deprecated 2019-06-09 */
    function utf8_strlen($str)
    {
        dbg_deprecated(PhpString::class . '::strlen()');
        return PhpString::strlen($str);
    }
}

if (!function_exists('utf8_substr')) {
    /** @deprecated 2019-06-09 */
    function utf8_substr($str, $offset, $length = null)
    {
        dbg_deprecated(PhpString::class . '::substr()');
        return PhpString::substr($str, $offset, $length);
    }
}

if (!function_exists('utf8_substr_replace')) {
    /** @deprecated 2019-06-09 */
    function utf8_substr_replace($string, $replacement, $start, $length = 0)
    {
        dbg_deprecated(PhpString::class . '::substr_replace()');
        return PhpString::substr_replace($string, $replacement, $start, $length);
    }
}

if (!function_exists('utf8_ltrim')) {
    /** @deprecated 2019-06-09 */
    function utf8_ltrim($str, $charlist = '')
    {
        dbg_deprecated(PhpString::class . '::ltrim()');
        return PhpString::ltrim($str, $charlist);
    }
}

if (!function_exists('utf8_rtrim')) {
    /** @deprecated 2019-06-09 */
    function utf8_rtrim($str, $charlist = '')
    {
        dbg_deprecated(PhpString::class . '::rtrim()');
        return PhpString::rtrim($str, $charlist);
    }
}

if (!function_exists('utf8_trim')) {
    /** @deprecated 2019-06-09 */
    function utf8_trim($str, $charlist = '')
    {
        dbg_deprecated(PhpString::class . '::trim()');
        return PhpString::trim($str, $charlist);
    }
}

if (!function_exists('utf8_strtolower')) {
    /** @deprecated 2019-06-09 */
    function utf8_strtolower($str)
    {
        dbg_deprecated(PhpString::class . '::strtolower()');
        return PhpString::strtolower($str);
    }
}

if (!function_exists('utf8_strtoupper')) {
    /** @deprecated 2019-06-09 */
    function utf8_strtoupper($str)
    {
        dbg_deprecated(PhpString::class . '::strtoupper()');
        return PhpString::strtoupper($str);
    }
}

if (!function_exists('utf8_ucfirst')) {
    /** @deprecated 2019-06-09 */
    function utf8_ucfirst($str)
    {
        dbg_deprecated(PhpString::class . '::ucfirst()');
        return PhpString::ucfirst($str);
    }
}

if (!function_exists('utf8_ucwords')) {
    /** @deprecated 2019-06-09 */
    function utf8_ucwords($str)
    {
        dbg_deprecated(PhpString::class . '::ucwords()');
        return PhpString::ucwords($str);
    }
}

if (!function_exists('utf8_deaccent')) {
    /** @deprecated 2019-06-09 */
    function utf8_deaccent($str, $case = 0)
    {
        dbg_deprecated(Clean::class . '::deaccent()');
        return Clean::deaccent($str, $case);
    }
}

if (!function_exists('utf8_romanize')) {
    /** @deprecated 2019-06-09 */
    function utf8_romanize($str)
    {
        dbg_deprecated(Clean::class . '::romanize()');
        return Clean::romanize($str);
    }
}

if (!function_exists('utf8_stripspecials')) {
    /** @deprecated 2019-06-09 */
    function utf8_stripspecials($str, $repl = '', $additional = '')
    {
        dbg_deprecated(Clean::class . '::stripspecials()');
        return Clean::stripspecials($str, $repl, $additional);
    }
}

if (!function_exists('utf8_strpos')) {
    /** @deprecated 2019-06-09 */
    function utf8_strpos($haystack, $needle, $offset = 0)
    {
        dbg_deprecated(PhpString::class . '::strpos()');
        return PhpString::strpos($haystack, $needle, $offset);
    }
}

if (!function_exists('utf8_tohtml')) {
    /** @deprecated 2019-06-09 */
    function utf8_tohtml($str, $all = false)
    {
        dbg_deprecated(Conversion::class . '::toHtml()');
        return Conversion::toHtml($str, $all);
    }
}

if (!function_exists('utf8_unhtml')) {
    /** @deprecated 2019-06-09 */
    function utf8_unhtml($str, $enties = false)
    {
        dbg_deprecated(Conversion::class . '::fromHtml()');
        return Conversion::fromHtml($str, $enties);
    }
}

if (!function_exists('utf8_to_unicode')) {
    /** @deprecated 2019-06-09 */
    function utf8_to_unicode($str, $strict = false)
    {
        dbg_deprecated(Unicode::class . '::fromUtf8()');
        return Unicode::fromUtf8($str, $strict);
    }
}

if (!function_exists('unicode_to_utf8')) {
    /** @deprecated 2019-06-09 */
    function unicode_to_utf8($arr, $strict = false)
    {
        dbg_deprecated(Unicode::class . '::toUtf8()');
        return Unicode::toUtf8($arr, $strict);
    }
}

if (!function_exists('utf8_to_utf16be')) {
    /** @deprecated 2019-06-09 */
    function utf8_to_utf16be($str, $bom = false)
    {
        dbg_deprecated(Conversion::class . '::toUtf16be()');
        return Conversion::toUtf16be($str, $bom);
    }
}

if (!function_exists('utf16be_to_utf8')) {
    /** @deprecated 2019-06-09 */
    function utf16be_to_utf8($str)
    {
        dbg_deprecated(Conversion::class . '::fromUtf16be()');
        return Conversion::fromUtf16be($str);
    }
}

if (!function_exists('utf8_bad_replace')) {
    /** @deprecated 2019-06-09 */
    function utf8_bad_replace($str, $replace = '')
    {
        dbg_deprecated(Clean::class . '::replaceBadBytes()');
        return Clean::replaceBadBytes($str, $replace);
    }
}

if (!function_exists('utf8_correctIdx')) {
    /** @deprecated 2019-06-09 */
    function utf8_correctIdx($str, $i, $next = false)
    {
        dbg_deprecated(Clean::class . '::correctIdx()');
        return Clean::correctIdx($str, $i, $next);
    }
}