MediaWiki
REL1_22
|
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. | |
static | isUtf8 ($value, $disableMbstring=false) |
Test whether a string is valid UTF-8. |
A collection of static methods to play with strings.
Definition at line 26 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 )
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 | to search |
string | $flags | regular expression flags |
Definition at line 252 of file StringUtils.php.
References $flags, and delimiterReplaceCallback().
Referenced by Sanitizer\normalizeCss(), CoreTagHooks\pre(), and Sanitizer\stripAllTags().
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 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/.
string | $startDelim | start delimiter |
string | $endDelim | end delimiter |
$callback | Callback: function to call on each match | |
$subject | String | |
string | $flags | regular expression flags |
MWException |
Definition at line 167 of file StringUtils.php.
References $flags, $output, and array().
Referenced by delimiterReplace(), 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 291 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
string | $separator | |
string | $subject |
Definition at line 304 of file StringUtils.php.
Referenced by CLDRPluralRuleEvaluator\evaluateCompiled(), explodeMarkup(), GenerateCollationData\generateFirstChars(), ConfEditorParseError\highlight(), and hungryDelimiterReplace().
static StringUtils::explodeMarkup | ( | $ | separator, |
$ | text | ||
) | [static] |
More or less "markup-safe" explode() Ignores any instances of the separator inside <...>
string | $separator | |
string | $text |
Definition at line 265 of file StringUtils.php.
References as, 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.
$startDelim | |
$endDelim | |
$replace | |
$subject |
Definition at line 131 of file StringUtils.php.
static StringUtils::isUtf8 | ( | $ | value, |
$ | disableMbstring = false |
||
) | [static] |
Test whether a string is valid UTF-8.
The function check for invalid byte sequences, overlong encoding but not for different normalisations.
This relies internally on the mbstring function mb_check_encoding() hardcoded to check against UTF-8. Whenever the function is not available we fallback to a pure PHP implementation. Setting $disableMbstring to true will skip the use of mb_check_encoding, this is mostly intended for unit testing our internal implementation.
string | $value | String to check |
boolean | $disableMbstring | Whether to use the pure PHP implementation instead of trying mb_check_encoding. Intended for unit testing. Default: false |
Definition at line 52 of file StringUtils.php.
References $value, array(), and as.
Referenced by DatabaseOracle\doQuery(), StringUtilsTest\testIsUtf8WithMbstring(), and StringUtilsTest\testIsUtf8WithPhpFallbackImplementation().