Erebot  latest
A modular IRC bot for PHP 5.3+
Erebot\TextWrapper Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

Erebot\TextWrapper::__construct (   $text)

Constructs a new instance of a text wrapper.

Parameters
string$textThe text to wrap.

Definition at line 42 of file TextWrapper.php.

Member Function Documentation

Erebot\TextWrapper::__toString ( )

Returns the wrapped text (untouched).

Return values
stringThe 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.

Return values
intThe custom count as an integer.
See also
http://php.net/countable.count.php

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.

Parameters
null | string$separator(optional) The separator to use while splitting the text. The default is to split it on whitespaces (' ').
Return values
intThe 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.

Return values
mixedCurrent element.
See also
http://php.net/iterator.current.php

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.

Parameters
int$startOffset 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 (' ').
Return values
stringAt 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.

Return values
scalarReturns scalar on success, or null on failure.
Note
Issues E_NOTICE on failure.
See also
http://php.net/iterator.key.php

Implements Iterator.

Definition at line 90 of file TextWrapper.php.

Erebot\TextWrapper::next ( )

Moves the current position to the next element.

Note
This method is called after each foreach loop.
See also
http://php.net/iterator.next.php

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.

Parameters
mixed$offsetAn offset to check for.
Return values
booltrue is returned when the offset exists, false when it doesn't.
See also
http://php.net/arrayaccess.offsetexists.php
Note
When using empty() ArrayAccess::offsetGet() will be called and checked for emptyness only if ArrayAccess::offsetExists() returns 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().

Parameters
mixed$offsetThe offset to retrieve.
Return values
mixedValue at the specified offset.
See also
http://php.net/arrayaccess.offsetget.php

Implements ArrayAccess.

Definition at line 124 of file TextWrapper.php.

Erebot\TextWrapper::offsetSet (   $offset,
  $value 
)

Assigns a value to the specified offset.

Parameters
mixed$offsetThe offset to assign the value to.
mixed$valueThe value to set.
See also
http://php.net/arrayaccess.offsetset.php

Implements ArrayAccess.

Definition at line 133 of file TextWrapper.php.

Erebot\TextWrapper::offsetUnset (   $offset)

Unsets an offset.

Parameters
mixed$offsetThe offset to unset.
See also
http://php.net/arrayaccess.offsetunset.php
Note
This method will not be called when type-casting to (unset).

Implements ArrayAccess.

Definition at line 139 of file TextWrapper.php.

Erebot\TextWrapper::rewind ( )

Rewinds back to the first element of the Iterator.

Note
This is the first method called when starting a foreach loop. It will not be executed after foreach loops.
See also
http://php.net/iterator.rewind.php

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.

Return values
booltrue if the current position is valid, false otherwise.
Note
If Iterator::valid() returns false, the foreach loop will be terminated.
See also
http://php.net/iterator.valid.php

Implements Iterator.

Definition at line 108 of file TextWrapper.php.


The documentation for this class was generated from the following file: