2004-08-29 10:30:23 +00:00
|
|
|
<?php
|
2004-09-03 23:00:01 +00:00
|
|
|
/**
|
|
|
|
|
* Some of these functions are adapted from places in MediaWiki.
|
|
|
|
|
* Should probably merge them for consistency.
|
|
|
|
|
*
|
2010-08-15 07:47:23 +00:00
|
|
|
* Copyright © 2004 Brion Vibber <brion@pobox.com>
|
2014-03-13 22:23:56 +00:00
|
|
|
* https://www.mediawiki.org/
|
2010-08-15 07:47:23 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup UtfNormal
|
2004-09-03 23:00:01 +00:00
|
|
|
*/
|
2004-08-29 10:30:23 +00:00
|
|
|
|
2015-03-07 09:27:42 +00:00
|
|
|
|
2015-03-31 18:41:43 +00:00
|
|
|
use UtfNormal\Utils;
|
2004-10-28 02:56:13 +00:00
|
|
|
/**
|
|
|
|
|
* Return UTF-8 sequence for a given Unicode code point.
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $codepoint Integer:
|
|
|
|
|
* @return String
|
2015-01-31 08:15:36 +00:00
|
|
|
* @throws InvalidArgumentException if fed out of range data.
|
2006-04-19 15:46:24 +00:00
|
|
|
* @public
|
2015-03-07 09:27:42 +00:00
|
|
|
* @deprecated since 1.25, use UtfNormal\Utils directly
|
2004-10-28 02:56:13 +00:00
|
|
|
*/
|
2004-08-29 10:30:23 +00:00
|
|
|
function codepointToUtf8( $codepoint ) {
|
2015-04-03 02:53:57 +00:00
|
|
|
return Utils::codepointToUtf8( $codepoint );
|
2004-08-29 10:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
2004-10-28 02:56:13 +00:00
|
|
|
/**
|
|
|
|
|
* Take a series of space-separated hexadecimal numbers representing
|
|
|
|
|
* Unicode code points and return a UTF-8 string composed of those
|
|
|
|
|
* characters. Used by UTF-8 data generation and testing routines.
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $sequence String
|
|
|
|
|
* @return String
|
2015-01-31 08:15:36 +00:00
|
|
|
* @throws InvalidArgumentException if fed out of range data.
|
2006-04-19 15:46:24 +00:00
|
|
|
* @private
|
2015-03-07 09:27:42 +00:00
|
|
|
* @deprecated since 1.25, use UtfNormal\Utils directly
|
2004-10-28 02:56:13 +00:00
|
|
|
*/
|
2004-08-29 10:30:23 +00:00
|
|
|
function hexSequenceToUtf8( $sequence ) {
|
2015-03-07 09:27:42 +00:00
|
|
|
return Utils::hexSequenceToUtf8( $sequence );
|
2004-08-29 10:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
2004-11-15 00:58:36 +00:00
|
|
|
/**
|
|
|
|
|
* Take a UTF-8 string and return a space-separated series of hex
|
|
|
|
|
* numbers representing Unicode code points. For debugging.
|
|
|
|
|
*
|
2015-03-07 09:27:42 +00:00
|
|
|
* @fixme this is private but extensions + maint scripts are using it
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $str UTF-8 string.
|
2004-11-15 00:58:36 +00:00
|
|
|
* @return string
|
2006-04-19 15:46:24 +00:00
|
|
|
* @private
|
2004-11-15 00:58:36 +00:00
|
|
|
*/
|
|
|
|
|
function utf8ToHexSequence( $str ) {
|
2013-03-18 01:09:02 +00:00
|
|
|
$buf = '';
|
|
|
|
|
foreach ( preg_split( '//u', $str, -1, PREG_SPLIT_NO_EMPTY ) as $cp ) {
|
2015-03-07 09:27:42 +00:00
|
|
|
$buf .= sprintf( '%04x ', UtfNormal\Utils::utf8ToCodepoint( $cp ) );
|
2013-03-18 01:09:02 +00:00
|
|
|
}
|
2014-04-24 19:33:40 +00:00
|
|
|
|
2013-03-18 01:09:02 +00:00
|
|
|
return rtrim( $buf );
|
2004-11-15 00:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
2004-10-28 02:56:13 +00:00
|
|
|
/**
|
|
|
|
|
* Determine the Unicode codepoint of a single-character UTF-8 sequence.
|
|
|
|
|
* Does not check for invalid input data.
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $char String
|
|
|
|
|
* @return Integer
|
|
|
|
|
* @public
|
2015-03-07 09:27:42 +00:00
|
|
|
* @deprecated since 1.25, use UtfNormal\Utils directly
|
2004-10-28 02:56:13 +00:00
|
|
|
*/
|
2004-08-29 10:30:23 +00:00
|
|
|
function utf8ToCodepoint( $char ) {
|
2015-03-07 09:27:42 +00:00
|
|
|
return Utils::utf8ToCodepoint( $char );
|
2004-08-29 10:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
2004-10-28 02:56:13 +00:00
|
|
|
/**
|
|
|
|
|
* Escape a string for inclusion in a PHP single-quoted string literal.
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $string string to be escaped.
|
2006-04-19 15:46:24 +00:00
|
|
|
* @return String: escaped string.
|
|
|
|
|
* @public
|
2015-03-07 09:27:42 +00:00
|
|
|
* @deprecated since 1.25, use UtfNormal\Utils directly
|
2004-10-28 02:56:13 +00:00
|
|
|
*/
|
2004-08-29 10:30:23 +00:00
|
|
|
function escapeSingleString( $string ) {
|
2015-03-07 09:27:42 +00:00
|
|
|
return Utils::escapeSingleString( $string );
|
2004-08-29 10:30:23 +00:00
|
|
|
}
|