|
Erebot
latest
A modular IRC bot for PHP 5.3+
|
A wrapper to easily split a string using a separator and deal with other operations related to separators. More...
Inheritance diagram for Erebot\TextWrapper:Public Member Functions | |
| __construct ($text) | |
| __toString () | |
| count () | |
| countTokens ($separator= ' ') | |
| current () | |
| getTokens ($start, $length=0, $separator= ' ') | |
| key () | |
| next () | |
| offsetExists ($offset) | |
| offsetGet ($offset) | |
| offsetSet ($offset, $value) | |
| offsetUnset ($offset) | |
| rewind () | |
| valid () | |
Protected Attributes | |
| $position | |
| Position in the text. | |
| $text | |
| The text wrapped by this instance. | |
A wrapper to easily split a string using a separator and deal with other operations related to separators.
Definition at line 28 of file TextWrapper.php.
| Erebot\TextWrapper::__construct | ( | $text | ) |
Constructs a new instance of a text wrapper.
| string | $text | The text to wrap. |
Definition at line 42 of file TextWrapper.php.
| Erebot\TextWrapper::__toString | ( | ) |
Returns the wrapped text (untouched).
| string | The text wrapped by this instance. |
Implements Erebot\Interfaces\TextWrapper.
Definition at line 72 of file TextWrapper.php.
| Erebot\TextWrapper::count | ( | ) |
Count elements of an object.
This method is executed when using the count() function on an object implementing the Countable interface.
| int | The custom count as an integer. |
Implements Countable.
Definition at line 78 of file TextWrapper.php.
| Erebot\TextWrapper::countTokens | ( | $separator = ' ' | ) |
Returns the number of chunks (tokens) obtained by splitting the wrapped text using the given separator. Whitespaces are squeezed together in the process, no matter what separator is actually used.
| null | string | $separator | (optional) The separator to use while splitting the text. The default is to split it on whitespaces (' '). |
| int | The number of tokens in the string. |
Implements Erebot\Interfaces\TextWrapper.
Definition at line 66 of file TextWrapper.php.
| Erebot\TextWrapper::current | ( | ) |
Returns the current element.
| mixed | Current element. |
Implements Iterator.
Definition at line 84 of file TextWrapper.php.
| Erebot\TextWrapper::getTokens | ( | $start, | |
$length = 0, |
|||
$separator = ' ' |
|||
| ) |
Splits the wrapped text using the given separator and returns only some of the chunks (tokens) as a new string. Whitespaces are squeezed together in the process, no matter what separator is actually used.
| int | $start | Offset of the first chunk to return (starting at 0). If negative, it starts at the end of the wrapped text. |
| null | int | $length | (optional) Number of chunks to return in the new string. If set to 0 (the default), returns all chunks from $start onward until the end of the wrapped text. |
| null | string | $separator | (optional) The separator to use while splitting the text. The default is to split it on whitespaces (' '). |
| string | At most $length chunks (if $length > 0) and its whitespaces squeezed. |
Implements Erebot\Interfaces\TextWrapper.
Definition at line 48 of file TextWrapper.php.
| Erebot\TextWrapper::key | ( | ) |
Returns the key of the current element.
| scalar | Returns scalar on success, or null on failure. |
E_NOTICE on failure.Implements Iterator.
Definition at line 90 of file TextWrapper.php.
| Erebot\TextWrapper::next | ( | ) |
Moves the current position to the next element.
Implements Iterator.
Definition at line 96 of file TextWrapper.php.
| Erebot\TextWrapper::offsetExists | ( | $offset | ) |
Whether or not an offset exists.
This method is executed when using isset() or empty() on objects implementing ArrayAccess.
| mixed | $offset | An offset to check for. |
| bool | true is returned when the offset exists, false when it doesn't. |
true. Implements ArrayAccess.
Definition at line 114 of file TextWrapper.php.
| Erebot\TextWrapper::offsetGet | ( | $offset | ) |
Returns the value at specified offset.
This method is executed when checking if offset is empty().
| mixed | $offset | The offset to retrieve. |
| mixed | Value at the specified offset. |
Implements ArrayAccess.
Definition at line 124 of file TextWrapper.php.
| Erebot\TextWrapper::offsetSet | ( | $offset, | |
| $value | |||
| ) |
Assigns a value to the specified offset.
| mixed | $offset | The offset to assign the value to. |
| mixed | $value | The value to set. |
Implements ArrayAccess.
Definition at line 133 of file TextWrapper.php.
| Erebot\TextWrapper::offsetUnset | ( | $offset | ) |
Unsets an offset.
| mixed | $offset | The offset to unset. |
(unset). Implements ArrayAccess.
Definition at line 139 of file TextWrapper.php.
| Erebot\TextWrapper::rewind | ( | ) |
Rewinds back to the first element of the Iterator.
Implements Iterator.
Definition at line 102 of file TextWrapper.php.
| Erebot\TextWrapper::valid | ( | ) |
Checks if current position is valid.
This method is called after Iterator::rewind() and Iterator::next() to check if the current position is valid.
| bool | true if the current position is valid, false otherwise. |
false, the foreach loop will be terminated.Implements Iterator.
Definition at line 108 of file TextWrapper.php.