2005-02-19 11:20:55 +01:00
|
|
|
<?php
|
2005-01-17 20:18:42 +01:00
|
|
|
/**
|
|
|
|
* UTF8 helper functions
|
|
|
|
*
|
2019-05-20 08:52:44 +02:00
|
|
|
* 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
|
|
|
|
*
|
2005-01-17 20:18:42 +01:00
|
|
|
* @author Andreas Gohr <andi@splitbrain.org>
|
|
|
|
*/
|
|
|
|
|
2019-05-20 08:52:44 +02:00
|
|
|
use dokuwiki\Utf8\Clean;
|
|
|
|
use dokuwiki\Utf8\Conversion;
|
|
|
|
use dokuwiki\Utf8\PhpString;
|
|
|
|
use dokuwiki\Utf8\Unicode;
|
|
|
|
|
2006-04-03 21:49:30 +02:00
|
|
|
/**
|
|
|
|
* check for mb_string support
|
|
|
|
*/
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!defined('UTF8_MBSTRING')) {
|
|
|
|
if (function_exists('mb_substr') && !defined('UTF8_NOMBSTRING')) {
|
|
|
|
define('UTF8_MBSTRING', 1);
|
|
|
|
} else {
|
|
|
|
define('UTF8_MBSTRING', 0);
|
2009-10-20 23:23:38 +02:00
|
|
|
}
|
2006-04-03 21:49:30 +02:00
|
|
|
}
|
|
|
|
|
2012-11-12 21:22:26 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!defined('UTF8_PREGSUPPORT')) {
|
|
|
|
define('UTF8_PREGSUPPORT', (bool)@preg_match('/^.$/u', 'ñ'));
|
2012-11-12 21:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!defined('UTF8_PROPERTYSUPPORT')) {
|
|
|
|
define('UTF8_PROPERTYSUPPORT', (bool)@preg_match('/^\pL$/u', 'ñ'));
|
2012-11-12 21:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (UTF8_MBSTRING) {
|
|
|
|
mb_internal_encoding('UTF-8');
|
2005-03-19 15:19:40 +01:00
|
|
|
}
|
2005-01-23 16:52:39 +01:00
|
|
|
|
2009-01-14 21:18:24 +01:00
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_isASCII')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_isASCII($str)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Clean::class . '::isASCII()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Clean::isASCII($str);
|
2006-04-03 21:25:37 +02:00
|
|
|
}
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2006-04-03 21:25:37 +02:00
|
|
|
|
2012-07-28 09:59:01 +02:00
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_strip')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_strip($str)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Clean::class . '::strip()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Clean::strip($str);
|
2012-07-28 09:59:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_check')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_check($str)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Clean::class . '::isUtf8()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Clean::isUtf8($str);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
|
|
|
}
|
2006-09-28 18:51:22 +02:00
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_basename')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_basename($path, $suffix = '')
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::basename()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::basename($path, $suffix);
|
2006-04-03 21:25:37 +02:00
|
|
|
}
|
2006-09-28 18:51:22 +02:00
|
|
|
}
|
2006-04-03 21:25:37 +02:00
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_strlen')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_strlen($str)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::strlen()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::strlen($str);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-06-07 21:44:56 +02:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_substr')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_substr($str, $offset, $length = null)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::substr()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::substr($str, $offset, $length);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-03-19 15:19:40 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_substr_replace')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_substr_replace($string, $replacement, $start, $length = 0)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::substr_replace()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::substr_replace($string, $replacement, $start, $length);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-03-19 15:19:40 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_ltrim')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_ltrim($str, $charlist = '')
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::ltrim()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::ltrim($str, $charlist);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-01-23 17:33:44 +01:00
|
|
|
}
|
2005-01-23 16:52:39 +01:00
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_rtrim')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_rtrim($str, $charlist = '')
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::rtrim()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::rtrim($str, $charlist);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-01-17 20:18:42 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_trim')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_trim($str, $charlist = '')
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::trim()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::trim($str, $charlist);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-01-17 20:18:42 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_strtolower')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_strtolower($str)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::strtolower()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::strtolower($str);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2008-10-26 09:42:39 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_strtoupper')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_strtoupper($str)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::strtoupper()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::strtoupper($str);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2008-10-26 09:42:39 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_ucfirst')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_ucfirst($str)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::ucfirst()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::ucfirst($str);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-01-17 20:18:42 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_ucwords')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_ucwords($str)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::ucwords()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::ucwords($str);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2006-02-10 21:06:27 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_deaccent')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_deaccent($str, $case = 0)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Clean::class . '::deaccent()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Clean::deaccent($str, $case);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-02-16 21:18:30 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_romanize')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_romanize($str)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Clean::class . '::romanize()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Clean::romanize($str);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-01-23 16:52:39 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_stripspecials')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_stripspecials($str, $repl = '', $additional = '')
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Clean::class . '::stripspecials()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Clean::stripspecials($str, $repl, $additional);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
|
|
|
}
|
2007-07-19 13:01:42 +02:00
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_strpos')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_strpos($haystack, $needle, $offset = 0)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(PhpString::class . '::strpos()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return PhpString::strpos($haystack, $needle, $offset);
|
2007-02-02 08:05:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_tohtml')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-10-10 09:22:24 +02:00
|
|
|
function utf8_tohtml($str, $all = false)
|
2019-05-19 23:49:53 +02:00
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Conversion::class . '::toHtml()');
|
2019-10-10 09:22:24 +02:00
|
|
|
return Conversion::toHtml($str, $all);
|
2007-02-02 08:05:09 +01:00
|
|
|
}
|
|
|
|
}
|
2009-01-14 21:18:24 +01:00
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_unhtml')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_unhtml($str, $enties = false)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Conversion::class . '::fromHtml()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Conversion::fromHtml($str, $enties);
|
2005-06-11 11:29:16 +02:00
|
|
|
}
|
2006-02-17 23:20:40 +01:00
|
|
|
}
|
2005-06-11 11:29:16 +02:00
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_to_unicode')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_to_unicode($str, $strict = false)
|
|
|
|
{
|
2019-06-10 16:12:59 +02:00
|
|
|
dbg_deprecated(Unicode::class . '::fromUtf8()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Unicode::fromUtf8($str, $strict);
|
2005-01-17 20:18:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('unicode_to_utf8')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function unicode_to_utf8($arr, $strict = false)
|
|
|
|
{
|
2019-06-10 16:12:59 +02:00
|
|
|
dbg_deprecated(Unicode::class . '::toUtf8()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Unicode::toUtf8($arr, $strict);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-01-17 20:18:42 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_to_utf16be')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_to_utf16be($str, $bom = false)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Conversion::class . '::toUtf16be()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Conversion::toUtf16be($str, $bom);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-10-17 22:04:31 +02:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf16be_to_utf8')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf16be_to_utf8($str)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Conversion::class . '::fromUtf16be()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Conversion::fromUtf16be($str);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2005-10-17 22:04:31 +02:00
|
|
|
}
|
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_bad_replace')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_bad_replace($str, $replace = '')
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Clean::class . '::replaceBadBytes()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Clean::replaceBadBytes($str, $replace);
|
2006-08-26 10:29:19 +02:00
|
|
|
}
|
|
|
|
}
|
2005-01-17 20:18:42 +01:00
|
|
|
|
2019-05-19 23:49:53 +02:00
|
|
|
if (!function_exists('utf8_correctIdx')) {
|
2019-06-09 22:23:21 +02:00
|
|
|
/** @deprecated 2019-06-09 */
|
2019-05-19 23:49:53 +02:00
|
|
|
function utf8_correctIdx($str, $i, $next = false)
|
|
|
|
{
|
2019-06-09 22:23:21 +02:00
|
|
|
dbg_deprecated(Clean::class . '::correctIdx()');
|
2019-05-20 08:52:44 +02:00
|
|
|
return Clean::correctIdx($str, $i, $next);
|
2009-01-14 21:18:24 +01:00
|
|
|
}
|
2006-08-26 11:53:11 +02:00
|
|
|
}
|