56 if ( !$disableMbstring && function_exists(
'mb_check_encoding' ) ) {
58 if ( $newPHP ===
null ) {
59 $newPHP = !mb_check_encoding(
"\xf4\x90\x80\x80",
'UTF-8' );
62 return mb_check_encoding(
$value,
'UTF-8' ) &&
63 ( $newPHP || preg_match(
"/\xf4[\x90-\xbf]|[\xf5-\xff]/S",
$value ) === 0 );
66 if ( preg_match(
"/[\x80-\xff]/S",
$value ) === 0 ) {
76 if ( $regexes ===
null ) {
77 $cont =
"[\x80-\xbf]";
84 "/[\\x00-\x7f]$cont/S",
87 "/[\xc0\xc1\xf5-\xff]/S",
90 "/[\xc2-\xdf](?!$cont$after)/S",
93 "/\xe0(?![\xa0-\xbf]$cont$after)/",
94 "/[\xe1-\xec\xee\xef](?!$cont{2}$after)/S",
95 "/\xed(?![\x80-\x9f]$cont$after)/",
98 "/\xf0(?![\x90-\xbf]$cont{2}$after)/",
99 "/[\xf1-\xf3](?!$cont{3}$after)/S",
100 "/\xf4(?![\x80-\x8f]$cont{2}$after)/",
104 foreach ( $regexes
as $regex ) {
105 if ( preg_match( $regex,
$value ) !== 0 ) {
132 $segments =
explode( $startDelim, $subject );
133 $output = array_shift( $segments );
134 foreach ( $segments
as $s ) {
135 $endDelimPos = strpos(
$s, $endDelim );
136 if ( $endDelimPos ===
false ) {
139 $output .= $replace . substr(
$s, $endDelimPos + strlen( $endDelim ) );
175 $encStart = preg_quote( $startDelim,
'!' );
176 $encEnd = preg_quote( $endDelim,
'!' );
177 $strcmp = strpos(
$flags,
'i' ) ===
false ?
'strcmp' :
'strcasecmp';
178 $endLength = strlen( $endDelim );
181 while ( $inputPos < strlen( $subject ) &&
182 preg_match(
"!($encStart)|($encEnd)!S$flags", $subject, $m, PREG_OFFSET_CAPTURE, $inputPos )
184 $tokenOffset = $m[0][1];
185 if ( $m[1][0] !=
'' ) {
187 $strcmp( $endDelim, substr( $subject, $tokenOffset, $endLength ) ) == 0
189 # An end match is present at the same location
191 $tokenLength = $endLength;
193 $tokenType =
'start';
194 $tokenLength = strlen( $m[0][0] );
196 } elseif ( $m[2][0] !=
'' ) {
198 $tokenLength = strlen( $m[0][0] );
200 throw new MWException(
'Invalid delimiter given to ' . __METHOD__ );
203 if ( $tokenType ==
'start' ) {
204 # Only move the start position if we haven't already found a start
205 # This means that START START END matches outer pair
206 if ( !$foundStart ) {
208 $inputPos = $tokenOffset + $tokenLength;
209 # Write out the non-matching section
210 $output .= substr( $subject, $outputPos, $tokenOffset - $outputPos );
211 $outputPos = $tokenOffset;
212 $contentPos = $inputPos;
215 # Move the input position past the *first character* of START,
216 # to protect against missing END when it overlaps with START
217 $inputPos = $tokenOffset + 1;
219 } elseif ( $tokenType ==
'end' ) {
223 substr( $subject, $outputPos, $tokenOffset + $tokenLength - $outputPos ),
224 substr( $subject, $contentPos, $tokenOffset - $contentPos )
228 # Non-matching end, write it out
229 $output .= substr( $subject, $inputPos, $tokenOffset + $tokenLength - $outputPos );
231 $inputPos = $outputPos = $tokenOffset + $tokenLength;
233 throw new MWException(
'Invalid delimiter given to ' . __METHOD__ );
236 if ( $outputPos < strlen( $subject ) ) {
237 $output .= substr( $subject, $outputPos );
260 $replacer->cb(), $subject,
$flags );
271 $placeholder =
"\x00";
274 $text = str_replace( $placeholder,
'', $text );
281 $items =
explode( $separator, $cleaned );
282 foreach ( $items
as $i => $str ) {
283 $items[$i] = str_replace( $placeholder, $separator, $str );
297 $string = str_replace(
'\\',
'\\\\', $string );
298 $string = str_replace(
'$',
'\\$', $string );
310 static function explode( $separator, $subject ) {
311 if ( substr_count( $subject, $separator ) > 1000 ) {
314 return new ArrayIterator(
explode( $separator, $subject ) );
328 return array( &$this,
'replace' );
352 $pairs[
"\$$i"] = $match;
355 return strtr( $this->r, $pairs );
371 $this->index = $index;
379 return str_replace( $this->
from, $this->to,
$matches[$this->index] );
428 return array(
'data' );
473 $this->
data = array_merge( $this->
data, $other->data );
500 if ( function_exists(
'fss_prep_replace' ) ) {
502 if ( $this->fss ===
false ) {
503 $this->fss = fss_prep_replace( $this->
data );
505 $result = fss_exec_replace( $this->fss, $subject );
552 $this->subjectLength = strlen(
$subject );
553 $this->delimLength = strlen(
$delim );
560 $this->endPos = strpos( $this->subject, $this->delim );
565 if ( $this->curPos ===
false ) {
567 } elseif ( $this->curPos >= $this->subjectLength ) {
569 } elseif ( $this->endPos ===
false ) {
570 $this->
current = substr( $this->subject, $this->curPos );
572 $this->
current = substr( $this->subject, $this->curPos, $this->endPos - $this->curPos );
591 if ( $this->endPos ===
false ) {
592 $this->curPos =
false;
595 if ( $this->curPos >= $this->subjectLength ) {
596 $this->endPos =
false;
598 $this->endPos = strpos( $this->subject, $this->delim, $this->curPos );
610 return $this->curPos !==
false;