r49043 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49042‎ | r49043 | r49044 >
Date:19:11, 30 March 2009
Author:rarohde
Status:ok
Tags:
Comment:
Adds fallback implementations of mb_strpos and mb_strrpos if native multi-byte support is not available.

See comments 65, 66, 68 on bug 6455.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -72,6 +72,54 @@
7373 }
7474 }
7575
 76+
 77+if( !function_exists( 'mb_strpos' ) ) {
 78+ /**
 79+ * Fallback implementation of mb_strpos, hardcoded to UTF-8.
 80+ * @param string $haystack
 81+ * @param string $needle
 82+ * @param string $offset optional start position
 83+ * @param string $encoding optional encoding; ignored
 84+ * @return int
 85+ */
 86+ function mb_strpos( $haystack, $needle, $offset = 0, $encoding="" ) {
 87+ $needle = preg_quote( $needle, '/' );
 88+
 89+ $ar = array();
 90+ preg_match( '/'.$needle.'/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
 91+
 92+ if( isset( $ar[0][1] ) ) {
 93+ return $ar[0][1];
 94+ } else {
 95+ return false;
 96+ }
 97+ }
 98+}
 99+
 100+if( !function_exists( 'mb_strrpos' ) ) {
 101+ /**
 102+ * Fallback implementation of mb_strrpos, hardcoded to UTF-8.
 103+ * @param string $haystack
 104+ * @param string $needle
 105+ * @param string $offset optional start position
 106+ * @param string $encoding optional encoding; ignored
 107+ * @return int
 108+ */
 109+ function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = "" ) {
 110+ $needle = preg_quote( $needle, '/' );
 111+
 112+ $ar = array();
 113+ preg_match_all( '/'.$needle.'/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
 114+
 115+ if( isset( $ar[0] ) && count( $ar[0] ) > 0 &&
 116+ isset( $ar[0][count($ar[0])-1][1] ) ) {
 117+ return $ar[0][count($ar[0])-1][1];
 118+ } else {
 119+ return false;
 120+ }
 121+ }
 122+}
 123+
76124 if ( !function_exists( 'array_diff_key' ) ) {
77125 /**
78126 * Exists in PHP 5.1.0+

Follow-up revisions

RevisionCommit summaryAuthorDate
r50997(Bug 6455) Add string function support to ParserFunctionsrarohde00:43, 26 May 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r39618Per discussion for bug 6455, merged functionality of StringFunctions into the...krimpet22:19, 18 August 2008
r39653Revert r39618 "Per discussion for bug 6455, merged functionality of StringFun...brion18:53, 19 August 2008

Status & tagging log