MediaWiki  REL1_20
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 26 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 166 of file StringUtils.php.

References delimiterReplaceCallback().

Referenced by Sanitizer\checkCss(), and CoreTagHooks\pre().

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
Exceptions:
MWException
Returns:
string

Definition at line 81 of file StringUtils.php.

References $output.

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

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 205 of file StringUtils.php.

Referenced by MovePageForm\doSubmit(), Linker\formatLinksInCommentCallback(), Title\moveSubpages(), MagicWord\replace(), and SyncFileBackend\replaceNamePaths().

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

Workalike for explode() with limited memory usage.

Returns an Iterator

Parameters:
$separator
$subject
Returns:
ArrayIterator|ExplodeIterator

Definition at line 218 of file StringUtils.php.

Referenced by Parser\doAllQuotes(), CLDRPluralRuleEvaluator\evaluateCompiled(), explodeMarkup(), GenerateCollationData\generateFirstChars(), ConfEditorParseError\highlight(), hungryDelimiterReplace(), and Parser\makeImage().

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 179 of file StringUtils.php.

References delimiterReplaceCallback(), and explode().

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 45 of file StringUtils.php.

References $output, $s, and explode().


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