From 9ea40294b44299fe52178f95800420ffe2925ab3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sat, 22 Oct 2005 19:37:55 +0000 Subject: [PATCH] * Added two new functions: lc() and uc(), they work like the function of the same name on Perl --- languages/LanguageUtf8.php | 59 ++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/languages/LanguageUtf8.php b/languages/LanguageUtf8.php index 67433b86a5..762ebe7807 100644 --- a/languages/LanguageUtf8.php +++ b/languages/LanguageUtf8.php @@ -37,41 +37,44 @@ if( function_exists( 'mb_strtoupper' ) ) { */ class LanguageUtf8 extends Language { - # These two functions use mbstring library, if it is loaded + # These functions use mbstring library, if it is loaded # or compiled and character mapping arrays otherwise. # In case of language-specific character mismatch # it should be dealt with in Language classes. + + function ucfirst( $str ) { + return $this->uc( $str, true ); + } - function ucfirst( $string ) { - /** - * On pages with many links we can get called a lot. - * The multibyte uppercase functions are relatively - * slow, so check first if we can use a faster ASCII - * version instead; it saves a few milliseconds. - */ - if( preg_match( '/^[\x80-\xff]/', $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 uc( $str, $first = false ) { + if ( function_exists( 'mb_strtoupper' ) ) + return $first ? mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 ) : mb_strtoupper( $str ); + else { + global $wikiUpperChars; + $x = $first ? '^' : ''; + return preg_replace( + "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e", + "strtr( \"\$1\" , \$wikiUpperChars )", + $str + ); } - return ucfirst( $string ); } - function lcfirst( $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 lcfirst( $str ) { + return $this->lc( $str, true ); + } + + function lc( $str, $first = false ) { + if ( function_exists( 'mb_strtolower' ) ) + return $first ? mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 ) : mb_strtolower( $str ); + else { + global $wikiLowerChars; + $x = $first ? '^' : ''; + return preg_replace( + "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e", + "strtr( \"\$1\" , \$wikiLowerChars )", + $str + ); } } -- 2.20.1