Declare and document $wgStatsdServer and $wgStatsdMetricPrefix
[lhc/web/wiklou.git] / includes / libs / normal / UtfNormalUtil.php
index ae88e73..ad9a2b9 100644 (file)
@@ -25,6 +25,8 @@
  * @ingroup UtfNormal
  */
 
+
+use UtfNormal\Utils;
 /**
  * Return UTF-8 sequence for a given Unicode code point.
  *
  * @return String
  * @throws InvalidArgumentException if fed out of range data.
  * @public
+ * @deprecated since 1.25, use UtfNormal\Utils directly
  */
 function codepointToUtf8( $codepoint ) {
-       if ( $codepoint < 0x80 ) {
-               return chr( $codepoint );
-       }
-
-       if ( $codepoint < 0x800 ) {
-               return chr( $codepoint >> 6 & 0x3f | 0xc0 ) .
-                       chr( $codepoint & 0x3f | 0x80 );
-       }
-
-       if ( $codepoint < 0x10000 ) {
-               return chr( $codepoint >> 12 & 0x0f | 0xe0 ) .
-                       chr( $codepoint >> 6 & 0x3f | 0x80 ) .
-                       chr( $codepoint & 0x3f | 0x80 );
-       }
-
-       if ( $codepoint < 0x110000 ) {
-               return chr( $codepoint >> 18 & 0x07 | 0xf0 ) .
-                       chr( $codepoint >> 12 & 0x3f | 0x80 ) .
-                       chr( $codepoint >> 6 & 0x3f | 0x80 ) .
-                       chr( $codepoint & 0x3f | 0x80 );
-       }
-
-       throw new InvalidArgumentException( "Asked for code outside of range ($codepoint)" );
+       return Utils::codepointToUtf8( $codepoint );
 }
 
 /**
@@ -68,21 +49,17 @@ function codepointToUtf8( $codepoint ) {
  * @return String
  * @throws InvalidArgumentException if fed out of range data.
  * @private
+ * @deprecated since 1.25, use UtfNormal\Utils directly
  */
 function hexSequenceToUtf8( $sequence ) {
-       $utf = '';
-       foreach ( explode( ' ', $sequence ) as $hex ) {
-               $n = hexdec( $hex );
-               $utf .= codepointToUtf8( $n );
-       }
-
-       return $utf;
+       return Utils::hexSequenceToUtf8( $sequence );
 }
 
 /**
  * Take a UTF-8 string and return a space-separated series of hex
  * numbers representing Unicode code points. For debugging.
  *
+ * @fixme this is private but extensions + maint scripts are using it
  * @param string $str UTF-8 string.
  * @return string
  * @private
@@ -90,7 +67,7 @@ function hexSequenceToUtf8( $sequence ) {
 function utf8ToHexSequence( $str ) {
        $buf = '';
        foreach ( preg_split( '//u', $str, -1, PREG_SPLIT_NO_EMPTY ) as $cp ) {
-               $buf .= sprintf( '%04x ', utf8ToCodepoint( $cp ) );
+               $buf .= sprintf( '%04x ', UtfNormal\Utils::utf8ToCodepoint( $cp ) );
        }
 
        return rtrim( $buf );
@@ -103,39 +80,10 @@ function utf8ToHexSequence( $str ) {
  * @param $char String
  * @return Integer
  * @public
+ * @deprecated since 1.25, use UtfNormal\Utils directly
  */
 function utf8ToCodepoint( $char ) {
-       # Find the length
-       $z = ord( $char[0] );
-       if ( $z & 0x80 ) {
-               $length = 0;
-               while ( $z & 0x80 ) {
-                       $length++;
-                       $z <<= 1;
-               }
-       } else {
-               $length = 1;
-       }
-
-       if ( $length != strlen( $char ) ) {
-               return false;
-       }
-
-       if ( $length == 1 ) {
-               return ord( $char );
-       }
-
-       # Mask off the length-determining bits and shift back to the original location
-       $z &= 0xff;
-       $z >>= $length;
-
-       # Add in the free bits from subsequent bytes
-       for ( $i = 1; $i < $length; $i++ ) {
-               $z <<= 6;
-               $z |= ord( $char[$i] ) & 0x3f;
-       }
-
-       return $z;
+       return Utils::utf8ToCodepoint( $char );
 }
 
 /**
@@ -144,11 +92,8 @@ function utf8ToCodepoint( $char ) {
  * @param string $string string to be escaped.
  * @return String: escaped string.
  * @public
+ * @deprecated since 1.25, use UtfNormal\Utils directly
  */
 function escapeSingleString( $string ) {
-       return strtr( $string,
-               array(
-                       '\\' => '\\\\',
-                       '\'' => '\\\''
-               ) );
+       return Utils::escapeSingleString( $string );
 }