[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/utils/ -> StringUtils.php (summary)

Methods to play with strings. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

File Size: 612 lines (17 kb)
Included or required:0 times
Referenced: 7 times
Includes or requires: 0 files

Defines 7 classes

StringUtils:: (7 methods):
  isUtf8()
  hungryDelimiterReplace()
  delimiterReplaceCallback()
  delimiterReplace()
  explodeMarkup()
  escapeRegexReplacement()
  explode()

Replacer:: (1 method):
  cb()

RegexlikeReplacer:: (2 methods):
  __construct()
  replace()

DoubleReplacer:: (2 methods):
  __construct()
  replace()

HashtableReplacer:: (2 methods):
  __construct()
  replace()

ReplacementArray:: (11 methods):
  __construct()
  __sleep()
  __wakeup()
  setArray()
  getArray()
  setPair()
  mergeArray()
  merge()
  removePair()
  removeArray()
  replace()

ExplodeIterator:: (7 methods):
  __construct()
  rewind()
  refreshCurrent()
  current()
  key()
  next()
  valid()


Class: StringUtils  - X-Ref

A collection of static methods to play with strings.

isUtf8( $value, $disableMbstring = false )   X-Ref
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.

param: string $value String to check
param: bool $disableMbstring Whether to use the pure PHP
return: bool Whether the given $value is a valid UTF-8 encoded string

hungryDelimiterReplace( $startDelim, $endDelim, $replace, $subject )   X-Ref
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.

param: string $startDelim
param: string $endDelim
param: string $replace
param: string $subject
return: string

delimiterReplaceCallback( $startDelim, $endDelim, $callback,$subject, $flags = '')   X-Ref
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/.

param: string $startDelim Start delimiter
param: string $endDelim End delimiter
param: callable $callback Function to call on each match
param: string $subject
param: string $flags Regular expression flags
return: string

delimiterReplace( $startDelim, $endDelim, $replace, $subject, $flags = '' )   X-Ref
Perform an operation equivalent to

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

param: string $startDelim Start delimiter regular expression
param: string $endDelim End delimiter regular expression
param: string $replace Replacement string. May contain $1, which will be
param: string $subject String to search
param: string $flags Regular expression flags
return: string The string with the matches replaced

explodeMarkup( $separator, $text )   X-Ref
More or less "markup-safe" explode()
Ignores any instances of the separator inside <...>

param: string $separator
param: string $text
return: array

escapeRegexReplacement( $string )   X-Ref
Escape a string to make it suitable for inclusion in a preg_replace()
replacement parameter.

param: string $string
return: string

explode( $separator, $subject )   X-Ref
Workalike for explode() with limited memory usage.
Returns an Iterator

param: string $separator
param: string $subject
return: ArrayIterator|ExplodeIterator

Class: Replacer  - X-Ref

Base class for "replacers", objects used in preg_replace_callback() and
StringUtils::delimiterReplaceCallback()

cb()   X-Ref

return: array

Class: RegexlikeReplacer  - X-Ref

Class to replace regex matches with a string similar to that used in preg_replace()

__construct( $r )   X-Ref

param: string $r

replace( $matches )   X-Ref

param: array $matches
return: string

Class: DoubleReplacer  - X-Ref

Class to perform secondary replacement within each replacement string

__construct( $from, $to, $index = 0 )   X-Ref

param: mixed $from
param: mixed $to
param: int $index

replace( $matches )   X-Ref

param: array $matches
return: mixed

Class: HashtableReplacer  - X-Ref

Class to perform replacement based on a simple hashtable lookup

__construct( $table, $index = 0 )   X-Ref

param: array $table
param: int $index

replace( $matches )   X-Ref

param: array $matches
return: mixed

Class: ReplacementArray  - X-Ref

Replacement array for FSS with fallback to strtr()
Supports lazy initialisation of FSS resource

__construct( $data = array()   X-Ref
Create an object with the specified replacement array
The array should have the same form as the replacement array for strtr()

param: array $data

__sleep()   X-Ref

return: array

__wakeup()   X-Ref
No description

setArray( $data )   X-Ref
Set the whole replacement array at once

param: array $data

getArray()   X-Ref

return: array|bool

setPair( $from, $to )   X-Ref
Set an element of the replacement array

param: string $from
param: string $to

mergeArray( $data )   X-Ref

param: array $data

merge( $other )   X-Ref

param: ReplacementArray $other

removePair( $from )   X-Ref

param: string $from

removeArray( $data )   X-Ref

param: array $data

replace( $subject )   X-Ref

param: string $subject
return: string

Class: ExplodeIterator  - X-Ref

An iterator which works exactly like:

foreach ( explode( $delim, $s ) as $element ) {
...
}

Except it doesn't use 193 byte per element
__construct( $delim, $subject )   X-Ref
Construct a DelimIterator

param: string $delim
param: string $subject

rewind()   X-Ref
No description

refreshCurrent()   X-Ref
No description

current()   X-Ref
No description

key()   X-Ref

return: int|bool Current position or boolean false if invalid

next()   X-Ref

return: string

valid()   X-Ref

return: bool



Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1