MediaWiki
1.28.0
|
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 preg_replace() with flags. More... | |
static | delimiterReplaceCallback ($startDelim, $endDelim, $callback, $subject, $flags= '') |
Perform an operation equivalent to preg_replace_callback() More... | |
static | escapeRegexReplacement ($string) |
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter. More... | |
static | explode ($separator, $subject) |
Workalike for explode() with limited memory usage. More... | |
static | explodeMarkup ($separator, $text) |
More or less "markup-safe" explode() Ignores any instances of the separator inside <...> More... | |
static | hungryDelimiterReplace ($startDelim, $endDelim, $replace, $subject) |
Perform an operation equivalent to preg_replace() More... | |
static | isUtf8 ($value) |
Test whether a string is valid UTF-8. More... | |
static | replaceMarkup ($search, $replace, $text) |
More or less "markup-safe" str_replace() Ignores any instances of the separator inside <...> More... | |
A collection of static methods to play with strings.
Definition at line 26 of file StringUtils.php.
|
static |
Perform an operation equivalent to preg_replace()
with flags.
Matches this code:
preg_replace( "!$startDelim(.*)$endDelim!$flags", $replace, $subject );
string | $startDelim | Start delimiter regular expression |
string | $endDelim | End delimiter regular expression |
string | $replace | Replacement string. May contain $1, which will be replaced by the text between the delimiters |
string | $subject | String to search |
string | $flags | Regular expression flags |
Definition at line 203 of file StringUtils.php.
References $flags.
Referenced by Sanitizer\normalizeCss(), CoreTagHooks\pre(), Sanitizer\stripAllTags(), and Parser\stripSectionName().
|
static |
Perform an operation equivalent to preg_replace_callback()
Matches this code:
preg_replace_callback( "!$startDelim(.*)$endDelim!s$flags", $callback, $subject );
If the start delimiter ends with an initial substring of the end delimiter, e.g. in the case of C-style comments, the behavior 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/
.
The implementation of delimiterReplaceCallback() is slower than hungryDelimiterReplace() but uses far less memory. The delimiters are literal strings, not regular expressions.
string | $startDelim | Start delimiter |
string | $endDelim | End delimiter |
callable | $callback | Function to call on each match |
string | $subject | |
string | $flags | Regular expression flags |
InvalidArgumentException |
Definition at line 113 of file StringUtils.php.
References $flags, and $output.
Referenced by explodeMarkup(), and replaceMarkup().
|
static |
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
string | $string |
Definition at line 268 of file StringUtils.php.
Referenced by MovePageForm\doSubmit(), Linker\formatLinksInComment(), Title\moveSubpages(), MagicWord\replace(), SyncFileBackend\replaceNamePaths(), FileBackendMultiWrite\substPaths(), and FileBackendMultiWrite\unsubstPaths().
|
static |
Workalike for explode() with limited memory usage.
string | $separator | |
string | $subject |
Definition at line 281 of file StringUtils.php.
Referenced by LanguageConverter\autoConvert(), Parser\doAllQuotes(), Parser\doTableStuff(), BlockLevelPass\execute(), explodeMarkup(), GenerateCollationData\generateFirstChars(), hungryDelimiterReplace(), Parser\makeImage(), LanguageConverter\parseCachedTable(), ConverterRule\parseFlags(), Parser\renderImageGallery(), and Parser\replaceInternalLinks2().
|
static |
More or less "markup-safe" explode() Ignores any instances of the separator inside <...>
string | $separator | |
string | $text |
Definition at line 217 of file StringUtils.php.
References as, delimiterReplaceCallback(), and explode().
|
static |
Perform an operation equivalent to preg_replace()
Matches this code:
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.
string | $startDelim | |
string | $endDelim | |
string | $replace | |
string | $subject |
Definition at line 74 of file StringUtils.php.
|
static |
Test whether a string is valid UTF-8.
The function check for invalid byte sequences, overlong encoding but not for different normalisations.
string | $value | String to check |
Definition at line 41 of file StringUtils.php.
References $value, and string.
Referenced by Language\checkTitleEncoding(), DatabaseOracle\doQuery(), and StringUtilsTest\testIsUtf8().
|
static |
More or less "markup-safe" str_replace() Ignores any instances of the separator inside <...>
string | $search | |
string | $replace | |
string | $text |
Definition at line 244 of file StringUtils.php.
References delimiterReplaceCallback().
Referenced by Parser\doTableStuff().