TeamSpeak 3 PHP Framework
1.1.12
|
Helper class for string handling. More...
Public Member Functions | |
__construct ($string) | |
The TeamSpeak3_Helper_String constructor. | |
replace ($search, $replace, $caseSensitivity=TRUE) | |
Replaces every occurrence of the string $search with the string $replace. | |
arg (array $args, $char="%") | |
This function replaces indexed or associative signs with given values. | |
startsWith ($pattern) | |
Returns true if the string starts with $pattern. | |
endsWith ($pattern) | |
Returns true if the string ends with $pattern. | |
findFirst ($needle) | |
Returns the position of the first occurrence of a char in a string. | |
findLast ($needle) | |
Returns the position of the last occurrence of a char in a string. | |
toLower () | |
Returns the lowercased string. | |
toUpper () | |
Returns the uppercased string. | |
contains ($pattern, $regexp=FALSE) | |
Returns true if the string contains $pattern. | |
substr ($start, $length=null) | |
Returns part of a string. | |
split ($separator, $limit=0) | |
Splits the string into substrings wherever $separator occurs. | |
append ($part) | |
Appends $part to the string. | |
prepend ($part) | |
Prepends $part to the string. | |
section ($separator, $first=0, $last=0) | |
Returns a section of the string. | |
resize ($size, $char="\0") | |
Sets the size of the string to $size characters. | |
trim () | |
Strips whitespaces (or other characters) from the beginning and end of the string. | |
escape () | |
Escapes a string using the TeamSpeak 3 escape patterns. | |
unescape () | |
Unescapes a string using the TeamSpeak 3 escape patterns. | |
filterAlnum () | |
Removes any non alphanumeric characters from the string. | |
filterAlpha () | |
Removes any non alphabetic characters from the string. | |
filterDigits () | |
Removes any non numeric characters from the string. | |
isInt () | |
Returns TRUE if the string is a numeric value. | |
toInt () | |
Returns the integer value of the string. | |
toCrc32 () | |
Calculates and returns the crc32 polynomial of the string. | |
toMd5 () | |
Calculates and returns the md5 checksum of the string. | |
toSha1 () | |
Calculates and returns the sha1 checksum of the string. | |
isUtf8 () | |
Returns TRUE if the string is UTF-8 encoded. | |
toUtf8 () | |
Converts the string to UTF-8. | |
toBase64 () | |
Encodes the string with MIME base64 and returns the result. | |
toHex () | |
Returns the hexadecimal value of the string. | |
spaceToPercent () | |
Replaces space characters with percent encoded strings. | |
toString () | |
Returns the string as a standard string. | |
__call ($function, $args) | |
Magical function that allows you to call PHP's built-in string functions on the TeamSpeak3_Helper_String object. | |
__toString () | |
Returns the character as a standard string. | |
count () | |
| |
rewind () | |
| |
valid () | |
| |
key () | |
| |
current () | |
| |
next () | |
| |
offsetExists ($offset) | |
| |
offsetGet ($offset) | |
| |
offsetSet ($offset, $value) | |
| |
offsetUnset ($offset) | |
| |
Static Public Member Functions | |
static | factory ($string) |
Returns a TeamSpeak3_Helper_String object for thegiven string. | |
static | fromBase64 ($base64) |
Decodes the string with MIME base64 and returns the result as an TeamSpeak3_Helper_String. | |
static | fromHex ($hex) |
Returns the TeamSpeak3_Helper_String based on a given hex value. | |
Protected Attributes | |
$string | |
$position = 0 | |
|
Helper class for string handling.
Definition at line 32 of file String.php.
TeamSpeak3_Helper_String::__construct | ( | $ | string | ) |
The TeamSpeak3_Helper_String constructor.
string | $string |
Definition at line 52 of file String.php.
{
$this->string = strval($string);
}
static TeamSpeak3_Helper_String::factory | ( | $ | string | ) | [static] |
Returns a TeamSpeak3_Helper_String object for thegiven string.
string | $string |
Definition at line 63 of file String.php.
Referenced by TeamSpeak3_Viewer_Text\fetchObject(), TeamSpeak3_Viewer_Html\fetchObject(), TeamSpeak3_Transport_Abstract\getAdapterType(), TeamSpeak3_Node_Abstract\getClass(), TeamSpeak3_Node_Abstract\getInfo(), TeamSpeak3_Helper_Convert\logEntry(), TeamSpeak3_Node_Host\permissionTree(), TeamSpeak3_Adapter_ServerQuery\prepare(), TeamSpeak3_Transport_TCP\readLine(), TeamSpeak3_Adapter_ServerQuery\request(), TeamSpeak3_Node_Host\serverGetByTSDNS(), TeamSpeak3_Node_Server\serverGroupGetProfiles(), TeamSpeak3_Node_Server\snapshotDeploy(), and TeamSpeak3_Node_Host\whoamiSet().
{ return new self($string); }
TeamSpeak3_Helper_String::replace | ( | $ | search, |
$ | replace, | ||
$ | caseSensitivity = TRUE |
||
) |
Replaces every occurrence of the string $search with the string $replace.
string | $search | |
string | $replace | |
boolean | $caseSensitivity |
Definition at line 76 of file String.php.
{ if($caseSensitivity) { $this->string = str_replace($search, $replace, $this->string); } else { $this->string = str_ireplace($search, $replace, $this->string); } return $this; }
TeamSpeak3_Helper_String::arg | ( | array $ | args, |
$ | char = "%" |
||
) |
This function replaces indexed or associative signs with given values.
array | $args | |
string | $char |
Definition at line 97 of file String.php.
Referenced by TeamSpeak3_Exception\prepareCustomMessage().
{ $args = array_reverse($args, TRUE); foreach($args as $key => $val) { $args[$char . $key] = $val; unset($args[$key]); } $this->string = strtr($this->string, $args); return $this; }
TeamSpeak3_Helper_String::startsWith | ( | $ | pattern | ) |
Returns true if the string starts with $pattern.
string | $pattern |
Definition at line 118 of file String.php.
References substr().
Referenced by TeamSpeak3_Adapter_ServerQuery_Event\__construct().
{ return (substr($this->string, 0, strlen($pattern)) == $pattern) ? TRUE : FALSE; }
TeamSpeak3_Helper_String::endsWith | ( | $ | pattern | ) |
Returns true if the string ends with $pattern.
string | $pattern |
Definition at line 129 of file String.php.
References substr().
{ return (substr($this->string, strlen($pattern)*-1) == $pattern) ? TRUE : FALSE; }
TeamSpeak3_Helper_String::findFirst | ( | $ | needle | ) |
Returns the position of the first occurrence of a char in a string.
string | $needle |
Definition at line 140 of file String.php.
{ return strpos($this->string, $needle); }
TeamSpeak3_Helper_String::findLast | ( | $ | needle | ) |
Returns the position of the last occurrence of a char in a string.
string | $needle |
Definition at line 151 of file String.php.
{ return strrpos($this->string, $needle); }
Returns the lowercased string.
Definition at line 161 of file String.php.
{ return new self(strtolower($this->string)); }
Returns the uppercased string.
Definition at line 171 of file String.php.
{ return new self(strtoupper($this->string)); }
TeamSpeak3_Helper_String::contains | ( | $ | pattern, |
$ | regexp = FALSE |
||
) |
Returns true if the string contains $pattern.
string | $pattern | |
booean | $regexp |
Definition at line 183 of file String.php.
Referenced by isInt().
{ if(empty($pattern)) { return TRUE; } if($regexp) { return (preg_match("/" . $pattern . "/i", $this->string)) ? TRUE : FALSE; } else { return (stristr($this->string, $pattern) !== FALSE) ? TRUE : FALSE; } }
TeamSpeak3_Helper_String::substr | ( | $ | start, |
$ | length = null |
||
) |
Returns part of a string.
integer | $start | |
integer | $length |
Definition at line 207 of file String.php.
Referenced by endsWith(), resize(), and startsWith().
TeamSpeak3_Helper_String::split | ( | $ | separator, |
$ | limit = 0 |
||
) |
Splits the string into substrings wherever $separator occurs.
string | $separator | |
integer | $limit |
Definition at line 221 of file String.php.
References count().
Referenced by TeamSpeak3_Adapter_ServerQuery_Event\__construct().
{ $parts = explode($separator, $this->string, ($limit) ? intval($limit) : $this->count()); foreach($parts as $key => $val) { $parts[$key] = new self($val); } return $parts; }
TeamSpeak3_Helper_String::append | ( | $ | part | ) |
Appends $part to the string.
string | $part |
Definition at line 239 of file String.php.
{ $this->string = $this->string . strval($part); return $this; }
TeamSpeak3_Helper_String::prepend | ( | $ | part | ) |
Prepends $part to the string.
string | $part |
Definition at line 252 of file String.php.
{ $this->string = strval($part) . $this->string; return $this; }
TeamSpeak3_Helper_String::section | ( | $ | separator, |
$ | first = 0 , |
||
$ | last = 0 |
||
) |
Returns a section of the string.
string | $separator | |
integer | $first | |
integer | $last |
Definition at line 267 of file String.php.
References count().
Referenced by TeamSpeak3_Adapter_ServerQuery\request(), and TeamSpeak3_Adapter_ServerQuery\wait().
{ $sections = explode($separator, $this->string); $total = count($sections); $first = intval($first); $last = intval($last); if($first > $total) return null; if($first > $last) $last = $first; for($i = 0; $i < $total; $i++) { if($i < $first || $i > $last) { unset($sections[$i]); } } $string = implode($separator, $sections); return new self($string); }
TeamSpeak3_Helper_String::resize | ( | $ | size, |
$ | char = "\0" |
||
) |
Sets the size of the string to $size characters.
integer | $size | |
string | $char |
Definition at line 298 of file String.php.
Strips whitespaces (or other characters) from the beginning and end of the string.
Definition at line 319 of file String.php.
{ $this->string = trim($this->string); return $this; }
Escapes a string using the TeamSpeak 3 escape patterns.
Definition at line 331 of file String.php.
References TeamSpeak3\getEscapePatterns().
{ foreach(TeamSpeak3::getEscapePatterns() as $search => $replace) { $this->string = str_replace($search, $replace, $this->string); } return $this; }
Unescapes a string using the TeamSpeak 3 escape patterns.
Definition at line 346 of file String.php.
References TeamSpeak3\getEscapePatterns().
{ $this->string = strtr($this->string, array_flip(TeamSpeak3::getEscapePatterns())); return $this; }
Removes any non alphanumeric characters from the string.
Definition at line 358 of file String.php.
{ $this->string = preg_replace("/[^[:alnum:]]/", "", $this->string); return $this; }
Removes any non alphabetic characters from the string.
Definition at line 370 of file String.php.
{ $this->string = preg_replace("/[^[:alpha:]]/", "", $this->string); return $this; }
Removes any non numeric characters from the string.
Definition at line 382 of file String.php.
{ $this->string = preg_replace("/[^[:digit:]]/", "", $this->string); return $this; }
Returns TRUE if the string is a numeric value.
Definition at line 394 of file String.php.
References contains().
{ return (is_numeric($this->string) && !$this->contains(".")) ? TRUE : FALSE; }
Returns the integer value of the string.
Definition at line 405 of file String.php.
{ if($this->string == pow(2, 63) || $this->string == pow(2, 64)) { return -1; } return ($this->string > pow(2, 31)) ? floatval($this->string) : intval($this->string); }
Calculates and returns the crc32 polynomial of the string.
Definition at line 420 of file String.php.
{ return crc32($this->string); }
Calculates and returns the md5 checksum of the string.
Definition at line 430 of file String.php.
{ return md5($this->string); }
Calculates and returns the sha1 checksum of the string.
Definition at line 440 of file String.php.
{ return sha1($this->string); }
Returns TRUE if the string is UTF-8 encoded.
This method searches for non-ascii multibyte sequences in the UTF-8 range.
Definition at line 451 of file String.php.
Referenced by toUtf8().
{ //return (utf8_encode(utf8_decode($this->string)) == $this->string) ? TRUE : FALSE; $pattern = array(); $pattern[] = "[\xC2-\xDF][\x80-\xBF]"; // non-overlong 2-byte $pattern[] = "\xE0[\xA0-\xBF][\x80-\xBF]"; // excluding overlongs $pattern[] = "[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}"; // straight 3-byte $pattern[] = "\xED[\x80-\x9F][\x80-\xBF]"; // excluding surrogates $pattern[] = "\xF0[\x90-\xBF][\x80-\xBF]{2}"; // planes 1-3 $pattern[] = "[\xF1-\xF3][\x80-\xBF]{3}"; // planes 4-15 $pattern[] = "\xF4[\x80-\x8F][\x80-\xBF]{2}"; // plane 16 return preg_match("%(?:" . implode("|", $pattern) . ")+%xs", $this->string);; }
Converts the string to UTF-8.
Definition at line 473 of file String.php.
References isUtf8().
{ if(!$this->isUtf8()) { $this->string = utf8_encode($this->string); } return $this; }
Encodes the string with MIME base64 and returns the result.
Definition at line 488 of file String.php.
{ return base64_encode($this->string); }
static TeamSpeak3_Helper_String::fromBase64 | ( | $ | base64 | ) | [static] |
Decodes the string with MIME base64 and returns the result as an TeamSpeak3_Helper_String.
string |
Definition at line 499 of file String.php.
Referenced by TeamSpeak3_Node_Server\snapshotDeploy().
{ return new self(base64_decode($base64)); }
Returns the hexadecimal value of the string.
Definition at line 509 of file String.php.
{ $hex = ""; foreach($this as $char) { $hex .= $char->toHex(); } return $hex; }
static TeamSpeak3_Helper_String::fromHex | ( | $ | hex | ) | [static] |
Returns the TeamSpeak3_Helper_String based on a given hex value.
string |
TeamSpeak3_Helper_Exception |
Definition at line 528 of file String.php.
Referenced by TeamSpeak3_Node_Server\snapshotDeploy(), and TeamSpeak3_Adapter_Update\syn().
{ $string = ""; if(strlen($hex)%2 == 1) { throw new TeamSpeak3_Helper_Exception("given parameter '" . $hex . "' is not a valid hexadecimal number"); } foreach(str_split($hex, 2) as $chunk) { $string .= chr(hexdec($chunk)); } return new self($string); }
Replaces space characters with percent encoded strings.
Definition at line 550 of file String.php.
{ return str_replace(" ", "%20", $this->string); }
Returns the string as a standard string.
Definition at line 560 of file String.php.
{
return $this->string;
}
TeamSpeak3_Helper_String::__call | ( | $ | function, |
$ | args | ||
) |
Magical function that allows you to call PHP's built-in string functions on the TeamSpeak3_Helper_String object.
string | $function | |
array | $args |
TeamSpeak3_Helper_Exception |
Definition at line 573 of file String.php.
References count().
{ if(!function_exists($function)) { throw new TeamSpeak3_Helper_Exception("cannot call undefined function '" . $function . "' on this object"); } if(count($args)) { if(($key = array_search($this, $args, TRUE)) !== FALSE) { $args[$key] = $this->string; } else { throw new TeamSpeak3_Helper_Exception("cannot call undefined function '" . $function . "' without the " . __CLASS__ . " object parameter"); } $return = call_user_func_array($function, $args); } else { $return = call_user_func($function, $this->string); } if(is_string($return)) { $this->string = $return; } else { return $return; } return $this; }
Returns the character as a standard string.
Definition at line 615 of file String.php.
{ return (string) $this->string; }
Definition at line 631 of file String.php.
{ $this->position = 0; }
Definition at line 639 of file String.php.
References count().
{ return $this->position < $this->count(); }
Definition at line 647 of file String.php.
{
return $this->position;
}
Definition at line 655 of file String.php.
{ return new TeamSpeak3_Helper_Char($this->string{$this->position}); }
Definition at line 663 of file String.php.
{ $this->position++; }
TeamSpeak3_Helper_String::offsetExists | ( | $ | offset | ) |
Definition at line 671 of file String.php.
Referenced by offsetGet(), offsetSet(), and offsetUnset().
{ return ($offset < strlen($this->string)) ? TRUE : FALSE; }
TeamSpeak3_Helper_String::offsetGet | ( | $ | offset | ) |
Definition at line 679 of file String.php.
References offsetExists().
{ return ($this->offsetExists($offset)) ? new TeamSpeak3_Helper_Char($this->string{$offset}) : null; }
TeamSpeak3_Helper_String::offsetSet | ( | $ | offset, |
$ | value | ||
) |
Definition at line 687 of file String.php.
References offsetExists().
{ if(!$this->offsetExists($offset)) return; $this->string{$offset} = strval($value); }
TeamSpeak3_Helper_String::offsetUnset | ( | $ | offset | ) |
Definition at line 697 of file String.php.
References offsetExists().
{ if(!$this->offsetExists($offset)) return; $this->string = substr_replace($this->string, "", $offset, 1); }
TeamSpeak3_Helper_String::$position = 0 [protected] |
Definition at line 44 of file String.php.