From aed481ba01bd30b158ce8abf6596938440e1b273 Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Mon, 16 Aug 2004 08:35:27 +0000 Subject: [PATCH] Commit in resource efficient lcfirst and ucfirst Uses PHP mbstring feature, in case it is compiled in. In case of language-dependant failures, those should be solved in Language classes. --- languages/LanguageUtf8.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/languages/LanguageUtf8.php b/languages/LanguageUtf8.php index 22c7832f74..2f60879ecd 100644 --- a/languages/LanguageUtf8.php +++ b/languages/LanguageUtf8.php @@ -4,6 +4,10 @@ if( defined( "MEDIAWIKI" ) ) { $wgInputEncoding = "UTF-8"; $wgOutputEncoding = "UTF-8"; +if (function_exists('mb_internal_encoding')) { + mb_internal_encoding('UTF-8'); +} + $wikiUpperChars = $wgMemc->get( $key1 = "$wgDBname:utf8:upper" ); $wikiLowerChars = $wgMemc->get( $key2 = "$wgDBname:utf8:lower" ); @@ -19,19 +23,27 @@ class LanguageUtf8 extends Language { function ucfirst( $string ) { # For most languages, this is a wrapper for ucfirst() # But that doesn't work right in a UTF-8 locale - global $wikiUpperChars; - return preg_replace ( - "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e", - "strtr ( \"\$1\" , \$wikiUpperChars )", - $string ); + if (function_exists('mb_strtoupper')) { + return mb_strtoupper(mb_substr($string,0,1)).mb_substr($string,1); + } else { + global $wikiUpperChars; + return preg_replace ( + "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e", + "strtr ( \"\$1\" , \$wikiUpperChars )", + $string ); + } } function lcfirst( $string ) { - global $wikiLowerChars; - return preg_replace ( - "/^([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e", - "strtr ( \"\$1\" , \$wikiLowerChars )", - $string ); + if (function_exists('mb_strtolower')) { + return mb_strtolower(mb_substr($string,0,1)).mb_substr($string,1); + } else { + global $wikiLowerChars; + return preg_replace ( + "/^([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e", + "strtr ( \"\$1\" , \$wikiLowerChars )", + $string ); + } } function stripForSearch( $string ) { -- 2.20.1