MediaWiki  REL1_19
StringUtils Class Reference

A collection of static methods to play with strings. More...

List of all members.

Static Public Member Functions

static delimiterReplace ($startDelim, $endDelim, $replace, $subject, $flags= '')
 Perform an operation equivalent to.
static delimiterReplaceCallback ($startDelim, $endDelim, $callback, $subject, $flags= '')
 Perform an operation equivalent to.
static escapeRegexReplacement ($string)
 Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
static explode ($separator, $subject)
 Workalike for explode() with limited memory usage.
static explodeMarkup ($separator, $text)
 More or less "markup-safe" explode() Ignores any instances of the separator inside <...>
static hungryDelimiterReplace ($startDelim, $endDelim, $replace, $subject)
 Perform an operation equivalent to.

Detailed Description

A collection of static methods to play with strings.

Definition at line 5 of file StringUtils.php.


Member Function Documentation

static StringUtils::delimiterReplace ( startDelim,
endDelim,
replace,
subject,
flags = '' 
) [static]

Perform an operation equivalent to.

preg_replace( "!$startDelim(.*)$endDelim!$flags", $replace, $subject )

Parameters:
$startDelimString: start delimiter regular expression
$endDelimString: end delimiter regular expression
$replaceString: replacement string. May contain $1, which will be replaced by the text between the delimiters
$subjectString to search
$flagsString: regular expression flags
Returns:
String: The string with the matches replaced

Definition at line 144 of file StringUtils.php.

References delimiterReplaceCallback().

Referenced by Sanitizer\normalizeCss(), CoreTagHooks\pre(), and Parser\stripSectionName().

Here is the call graph for this function:

Here is the caller graph for this function:

static StringUtils::delimiterReplaceCallback ( startDelim,
endDelim,
callback,
subject,
flags = '' 
) [static]

Perform an operation equivalent to.

preg_replace_callback( "!$startDelim(.*)$endDelim!s$flags", $callback, $subject )

This implementation is slower than hungryDelimiterReplace but uses far less memory. The delimiters are literal strings, not regular expressions.

If the start delimiter ends with an initial substring of the end delimiter, e.g. in the case of C-style comments, the behaviour differs from the model regex. In this implementation, the end must share no characters with the start, so e.g. /*\/ is not considered to be both the start and end of a comment. /*\/xy/*\/ is considered to be a single comment with contents /xy/.

Parameters:
$startDelimString: start delimiter
$endDelimString: end delimiter
$callbackCallback: function to call on each match
$subjectString
$flagsString: regular expression flags
Returns:
string

Definition at line 59 of file StringUtils.php.

References $output.

Referenced by delimiterReplace(), LinkMarkerReplacer\expand(), and explodeMarkup().

Here is the caller graph for this function:

static StringUtils::escapeRegexReplacement ( string) [static]

Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.

Parameters:
$stringString
Returns:
String

Definition at line 183 of file StringUtils.php.

Referenced by MovePageForm\doSubmit(), Linker\formatLinksInCommentCallback(), Title\moveSubpages(), MagicWord\replace(), FileBackendMultiWrite\substPaths(), and FileBackendMultiWrite\unsubstPaths().

Here is the caller graph for this function:

static StringUtils::explode ( separator,
subject 
) [static]
static StringUtils::explodeMarkup ( separator,
text 
) [static]

More or less "markup-safe" explode() Ignores any instances of the separator inside <...>

Parameters:
$separatorString
$textString
Returns:
array

Definition at line 157 of file StringUtils.php.

References delimiterReplaceCallback(), and explode().

Referenced by Parser\doTableStuff().

Here is the call graph for this function:

Here is the caller graph for this function:

static StringUtils::hungryDelimiterReplace ( startDelim,
endDelim,
replace,
subject 
) [static]

Perform an operation equivalent to.

preg_replace( "!$startDelim(.*?)$endDelim!", $replace, $subject );

except that it's worst-case O(N) instead of O(N^2)

Compared to delimiterReplace(), this implementation is fast but memory- hungry and inflexible. The memory requirements are such that I don't recommend using it on anything but guaranteed small chunks of text.

Parameters:
$startDelim
$endDelim
$replace
$subject
Returns:
string

Definition at line 24 of file StringUtils.php.

References $output, and explode().

Here is the call graph for this function:


The documentation for this class was generated from the following file: