MediaWiki
REL1_19
|
A collection of static methods to play with strings. More...
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. |
A collection of static methods to play with strings.
Definition at line 5 of file StringUtils.php.
static StringUtils::delimiterReplace | ( | $ | startDelim, |
$ | endDelim, | ||
$ | replace, | ||
$ | subject, | ||
$ | flags = '' |
||
) | [static] |
Perform an operation equivalent to.
preg_replace( "!$startDelim(.*)$endDelim!$flags", $replace, $subject )
$startDelim | String: start delimiter regular expression |
$endDelim | String: end delimiter regular expression |
$replace | String: replacement string. May contain $1, which will be replaced by the text between the delimiters |
$subject | String to search |
$flags | String: regular expression flags |
Definition at line 144 of file StringUtils.php.
References delimiterReplaceCallback().
Referenced by Sanitizer\normalizeCss(), CoreTagHooks\pre(), and Parser\stripSectionName().
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/.
$startDelim | String: start delimiter |
$endDelim | String: end delimiter |
$callback | Callback: function to call on each match |
$subject | String |
$flags | String: regular expression flags |
Definition at line 59 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.
$string | String |
Definition at line 183 of file StringUtils.php.
Referenced by MovePageForm\doSubmit(), Linker\formatLinksInCommentCallback(), Title\moveSubpages(), MagicWord\replace(), FileBackendMultiWrite\substPaths(), and FileBackendMultiWrite\unsubstPaths().
static StringUtils::explode | ( | $ | separator, |
$ | subject | ||
) | [static] |
Workalike for explode() with limited memory usage.
Returns an Iterator
$separator | |
$subject |
Definition at line 196 of file StringUtils.php.
Referenced by LanguageConverter\autoConvert(), Parser\doAllQuotes(), Parser\doBlockLevels(), Parser\doTableStuff(), explodeMarkup(), GenerateCollationData\generateFirstChars(), ConfEditorParseError\highlight(), hungryDelimiterReplace(), Parser\makeImage(), LanguageConverter\parseCachedTable(), ConverterRule\parseFlags(), Parser\renderImageGallery(), and Parser\replaceInternalLinks2().
static StringUtils::explodeMarkup | ( | $ | separator, |
$ | text | ||
) | [static] |
More or less "markup-safe" explode() Ignores any instances of the separator inside <...>
$separator | String |
$text | String |
Definition at line 157 of file StringUtils.php.
References delimiterReplaceCallback(), and explode().
Referenced by Parser\doTableStuff().
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.
$startDelim | |
$endDelim | |
$replace | |
$subject |
Definition at line 24 of file StringUtils.php.
References $output, and explode().