Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- namespace ILLI\Core\Util;
- use ILLI\Core\Std\DefaultStatic\__import_IDefaultStatic;
- use ILLI\Core\Std\IDefaultStatic;
- use ILLI\Core\Util\Arr;
- class Str implements IDefaultStatic
- {
- use __import_IDefaultStatic;
- #:php:
- static function explode($__string, $__delimiter = __str::SPACE, $__limit = NULL)
- {
- return 0x02 >= func_num_args()
- ? explode($__delimiter, $__string)
- : explode($__delimiter, $__string, $__limit);
- }
- static function f($__format, ...$__data)
- {
- $a = func_get_args();
- return sprintf(...$a);
- }
- static function join(array $__data, $__delimiter = __str::DEVOID)
- {
- return join($__delimiter, $__data);
- }
- static function len($__string)
- {
- return strlen($__string);
- }
- static function lc($__string)
- {
- return strtolower($__string);
- }
- static function lcf($__string)
- {
- return ucfirst($__string);
- }
- static function lcw($__string)
- {
- return ucwords($__string);
- }
- static function pad($__string, $__length, $__delimiter, $__case)
- {
- return str_pad($__string, $__length, $__delimiter, $__case);
- }
- static function pos($__string, $__needle, $__offset = 0x00)
- {
- return strpos($__string, $__needle, $__offset);
- }
- static function pregMatch($__string, $__pattern, $__flag = 0x00, $__offset = 0x00)
- {
- if(0x02 >= func_num_args())
- return preg_match($__pattern, $__string);
- preg_match($__pattern, $__string, $matches, $__flag, $__offset);
- return $matches;
- }
- static function split($__string, $__length = 0x01)
- {
- return str_split($__string, $__length);
- }
- static function sub($__string, $__start, $__length = NULL)
- {
- return 0x02 >= func_num_args()
- ? substr($__string, $__start)
- : substr($__string, $__start, $__length);
- }
- static function tr($__string, $__from, $__to = NULL)
- {
- return 0x02 >= func_num_args()
- ? strtr($__string, $__from)
- : strtr($__string, $__from, $__to);
- }
- static function uc($__string)
- {
- return strtoupper($__string);
- }
- static function ucf($__string)
- {
- return ucfirst($__string);
- }
- static function ucw($__string)
- {
- return ucwords($__string);
- }
- static function repeat($__string, $__length)
- {
- return str_repeat($__string, $__length);
- }
- static function replace($__string, $__search, $__replace)
- {
- return str_replace($__search, $__replace, $__string);
- }
- #::
- #:crypt:
- static function encrypt($__string, $__secret)
- {
- return mcrypt_encrypt(MCRYPT_BLOWFISH, $__secret, utf8_encode($__string), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB), MCRYPT_RAND));
- }
- static function decrypt($__string, $__secret)
- {
- return mcrypt_decrypt(MCRYPT_BLOWFISH, $__secret, $__string, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB), MCRYPT_RAND));
- }
- #::
- #:generator:
- static function hash($__string, array $__options = [])
- {
- $__options +=
- [
- 'type' => 'sha512',
- 'salt' => FALSE,
- 'key' => FALSE,
- 'raw' => FALSE
- ];
- if(TRUE === $__options['salt'])
- $__string = $__options['salt'].$__string;
- return TRUE === $__options['key']
- ? hash_hmac($__options['type'], $__string, $__options['key'], $__options['raw'])
- : hash($__options['type'], $__string, $__options['raw']);
- }
- static function rand($__bytes, array $__options = [])
- {
- $__options += ['encode' => NULL];
- static $__fn_STATIC_rand;
- #:rand:
- isset($__fn_STATIC_rand) ?: $__fn_STATIC_rand = function($__bytes)
- {
- $r = __str::DEVOID;
- for($i = 0x00; $i < $__bytes; $i++)
- $r .= chr(mt_rand(0x00, 0xFF));
- return $r;
- };
- #::
- $r = $__fn_STATIC_rand($__bytes);
- return ($__options['encode'] === static::ENCODE_BASE_64)
- ? static::tr(rtrim(base64_encode($r), __str::EQ), __str::PLUS, __str::DOT)
- : $r;
- }
- #::
- #:format:
- static function bom($__string = NULL)
- {
- return chr(255).chr(254).$__string;
- }
- static function compare($__left, $__right)
- {
- $r = TRUE;
- if(($l = static::len($__left)) !== static::len($__right))
- return FALSE;
- for($i = 0x00; $i < $l; $i++)
- $r = $r && ($__left[$i] === $__right[$i]);
- return $r;
- }
- static function hexdump($__string, array $__options = [])
- {
- $__options +=
- [
- 'width' => 0x10,
- 'eol' => __str::EOL,
- 'space' => __str::SPACE,
- 'raw' => FALSE,
- 'invisible' => __str::INVISIBLE,
- 'pattern' => '{:x} : {:line} : {:part}',
- 'from' => 0x20,
- 'to' => 0x7E
- ];
- static $__fn_STATIC_from, $__fn_STATIC_to, $__fn_STATIC_walk;
- #:walk:
- isset($__fn_STATIC_walk) ?: $__fn_STATIC_walk = function($__start, $__stop, callable $__Handler, array $__options = [])
- {
- $r = [];
- for($i = $__start; $i <= $__stop; $i++)
- $r[] = $__Handler($i, $__options);
- return static::join($r);
- };
- #::
- #:from:
- isset($__fn_STATIC_from) ?: $__fn_STATIC_from = $__fn_STATIC_walk
- (
- 0x00, 0xFF,
- function($__i, array $__options = []){ return chr($__i); },
- $__options
- );
- #::
- #:to:
- isset($__fn_STATIC_to) ?: $__fn_STATIC_to = $__fn_STATIC_walk
- (
- 0x00, 0xFF,
- function($__i, array $__options = []){ return $__i >= $__options['from'] && $__i <= $__options['to'] ? chr($__i) : $__options['invisible']; },
- $__options
- );
- #::
- $c = static::split(static::tr($__string, $__fn_STATIC_from, $__fn_STATIC_to), $__options['width']);
- $p = static::split($__string, $__options['width']);
- $h = static::split(bin2hex($__string), $__options['width'] * 0x02);
- $o = 0;
- $r = [];
- foreach($h as $i => $l)
- {
- $s = sizeOf($l = static::split($l, 0x02)) === $__options['width'] ?: $l += array_fill($s, $__options['width'] - $s, __str::LITSPACE);
- $r[] = TRUE === $__options['raw']
- ? ['offset' => $o, 'line' => $l, 'part' => $c[$i], 'orig' => $p[$i]]
- : static::insert($__options['pattern'], ['x' => sprintf('%8X', $o), 'line' => static::join($l, $__options['space']), 'part' => $c[$i]]);
- $o += $__options['width'];
- }
- if(TRUE === $__options['raw'])
- return $r;
- return FALSE === $__options['eol']
- ? $r
- : static::join($r, $__options['eol']);
- }
- static function sequence(array $__data, array $__options = [])
- {
- return static::__sequence($__data, $__options);
- }
- protected static function __sequence($__data, $__options, $__level = 0x01)
- {
- if(FALSE === is_array($__data))
- return $__data;
- if([] === $__data)
- return '[]';
- $__options +=
- [
- 'eol' => __str::EOL,
- 'indent' => 0x00,
- 'head' => 0x18,
- 'padding' => 0x04,
- 'text' => 0x34,
- ];
- $r = [];
- $i = static::repeat('.', $__options['indent']);
- if($__level === 0x01)
- {
- foreach($__data as $k => $v)
- {
- $_k = static::explodeEoL(wordwrap($k, $__options['head'], __str::EOL));
- $_v = is_array($v)
- ? static::explodeEoL(static::__sequence($v, $__options, $__level + 0x01))
- : static::explodeEoL(wordwrap($v, $__options['text'], __str::EOL));
- $a = [];
- foreach(array_keys(count($_k) > count($_v) ? $_k : $_v) as $l)
- {
- $a[] = sprintf(sprintf('%%%ds', $__options['head']), isset($_k[$l]) ? trim($_k[$l]) : '');
- !isset($_v[$l]) ?: $a[] = ' ';
- $a[] = trim(sprintf(sprintf('%%-%ds', $__options['text']), isset($_v[$l]) ? trim($_v[$l]) : ''));
- $a[] = $__options['eol'].$i;
- }
- $r[] = $i.join('', $a);
- }
- }
- else
- {
- foreach($__data as $k => $v)
- {
- $_k = static::explodeEoL(wordwrap($k, $__options['text'], __str::EOL));
- $_v = is_array($v)
- ? static::explodeEoL(static::__sequence($v, $__options, $__level + 0x01))
- : static::explodeEoL(wordwrap($v, $__options['text'], __str::EOL));
- $a = [];
- foreach($_k as $l)
- {
- if(is_integer($k))
- continue;
- $a[] = $l === '' ? '' : sprintf(sprintf('%%-%ds', $__options['text']), $l);
- $a[] = static::repeat('-', $__options['text']);
- }
- foreach($_v as $l)
- {
- if($l === '')
- continue;
- $a[] = sprintf(sprintf('%%-%ds', $__options['text']), $l);
- is_integer($k) ?: $a[] = $__options['eol'];
- }
- $r[] = join($__options['eol'], $a);
- }
- }
- return join($__options['eol'], $r);
- }
- #::
- #:tests:
- static function isUtf8($__mixed)
- {
- return TRUE === is_string($__mixed) && 0x01 === preg_match('/^.*$/us', $__mixed);
- }
- #::
- #:aggregate:
- static function concat($__stringN)
- {
- return static::join(func_get_args(), __str::DEVOID);
- }
- static function lcfi($__string)
- {
- return static::lcf(static::uc($__string));
- }
- static function lcwi($__string)
- {
- return static::lcw(static::uc($__string));
- }
- static function match($__string, $__pattern, array $__options = [])
- {
- $__options += [
- 'matches' => FALSE,
- 'mod' => '',
- 'flag' => 0,
- 'offset' => 0,
- 'escapeSlash' => TRUE,
- 'format' => FALSE
- ];
- if(FALSE !== $__options['format'])
- $__pattern = static::insert($__pattern, $__options['format']);
- $__pattern = static::concat
- (
- __str::SLASH,
- TRUE === $__options['escapeSlash']
- ? static::replace($__pattern, __str::SLASH, __str::ESLASH)
- : $__pattern,
- __str::SLASH,
- $__options['mod']
- );
- return FALSE === $__options['matches']
- ? (bool) static::pregMatch($__pattern, $__string)
- : static::pregMatch($__pattern, $__string, $__options['flag'], $__options['offset']);
- }
- static function ucfi($__string)
- {
- return static::ucf(static::lc($__string));
- }
- static function ucwi($__string)
- {
- return static::ucw(static::lc($__string));
- }
- #::
- #:chr:
- static function insert($__string, $__insert, $__index, $__concat = TRUE, $__length = 0x01)
- {
- $r = static::split($__string, $__length);
- array_splice($r, $__index, 0x00, $__insert);
- return TRUE === $__concat ? static::join($r) : $r;
- }
- static function merge($__string, array $__data, $__concat = TRUE, $__length = 0x01)
- {
- $r = static::split($__string, $__length);
- foreach($__data as $k => $v)
- $r[$k] = $v;
- return TRUE === $__concat ? static::join($r) : $r;
- }
- static function range($__string, $__index, $__count, $__concat = TRUE, $__length = 0x01)
- {
- $r = static::split($__string, $__length);
- return TRUE === $__concat
- ? [
- 0x00 => static::join(array_slice($r, 0x00, $__index)),
- 0x01 => static::join(array_slice($r, $__index, $__count)),
- 0x02 => static::join(array_slice($r, $__index + $__count))
- ]
- : [
- 0x00 => array_slice($r, 0x00, $__index),
- 0x01 => array_slice($r, $__index, $__count),
- 0x02 => array_slice($r, $__index + $__count)
- ];
- }
- static function remove($__string, $__index, $__concat = TRUE, $__length = 0x01)
- {
- $r = static::split($__string, $__length);
- unset($r[$__index]);
- return TRUE === $__concat ? static::join($r) : $r;
- }
- static function removeRange($__string, $__index, $__count, $__concat = TRUE, $__length = 0x01)
- {
- $r = static::range($__string, $__index, $__count, TRUE, $__length);
- unset($r[0x01]);
- return TRUE === $__concat ? static::join($r) : $r;
- }
- static function reverse($__string, $__concat = TRUE, $__length = 0x01)
- {
- $r = array_reverse(static::split($__string, $__length));
- return TRUE === $__concat ? static::join($r) : $r;
- }
- static function reverseRange($__string, $__index, $__count, $__concat = TRUE, $__length = 0x01)
- {
- $r = static::range($__string, $__index, $__count, FALSE, $__length);
- $r[0x01] = array_reverse($r[0x01]);
- $r[0x00] = static::join($r[0x00]);
- $r[0x01] = static::join($r[0x01]);
- $r[0x02] = static::join($r[0x02]);
- return TRUE === $__concat ? static::join($r) : $r;
- }
- #::
- #:sequence:
- static function insertAt($__string, $__delimiter, $__insert, $__index, $__concat = TRUE, $__limit = NULL)
- {
- $r = 0x05 >= func_num_args()
- ? static::explode($__string, $__delimiter)
- : static::explode($__string, $__delimiter, $__limit);
- array_splice($r, $__index, 0x00, $__insert);
- return TRUE === $__concat ? static::join($r, $__delimiter) : $r;
- }
- static function mergeAt($__string, $__delimiter, array $__data, $__concat = TRUE, $__limit = NULL)
- {
- $r = 0x04 >= func_num_args()
- ? static::explode($__string, $__delimiter)
- : static::explode($__string, $__delimiter, $__limit);
- foreach($__data as $k => $v)
- $r[$k] = $v;
- return TRUE === $__concat ? static::join($r, $__delimiter) : $r;
- }
- static function rangeAt($__string, $__delimiter, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- $r = 0x05 >= func_num_args()
- ? static::explode($__string, $__delimiter)
- : static::explode($__string, $__delimiter, $__limit);
- return TRUE === $__concat
- ? [
- 0x00 => static::join(array_slice($r, 0x00, $__index), $__delimiter),
- 0x01 => static::join(array_slice($r, $__index, $__count), $__delimiter),
- 0x02 => static::join(array_slice($r, $__index + $__count), $__delimiter)
- ]
- : [
- 0x00 => array_slice($r, 0x00, $__index),
- 0x01 => array_slice($r, $__index, $__count),
- 0x02 => array_slice($r, $__index + $__count)
- ];
- }
- static function removeAt($__string, $__delimiter, $__index, $__concat = TRUE, $__limit = NULL)
- {
- $r = 0x03 >= func_num_args()
- ? static::explode($__string, $__delimiter)
- : static::explode($__string, $__delimiter, $__limit);
- unset($r[$__index]);
- return TRUE === $__concat ? static::join($r, $__delimiter) : $r;
- }
- static function removeRangeAt($__string, $__delimiter, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- $r = 0x05 >= func_num_args()
- ? static::rangeAt($__string, $__delimiter, $__index, $__count, TRUE)
- : static::rangeAt($__string, $__delimiter, $__index, $__count, TRUE, $__limit);
- unset($r[0x01]);
- return TRUE === $__concat ? static::join($r, $__delimiter) : $r;
- }
- static function reverseAt($__string, $__delimiter, $__concat = TRUE, $__limit = NULL)
- {
- $r = 0x03 >= func_num_args()
- ? static::explode($__string, $__delimiter)
- : static::explode($__string, $__delimiter, $__limit);
- $r = array_reverse($r);
- return TRUE === $__concat ? static::join($r, $__delimiter) : $r;
- }
- static function reverseRangeAt($__string, $__delimiter, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- $r = 0x05 >= func_num_args()
- ? static::rangeAt($__string, $__delimiter, $__index, $__count, FALSE)
- : static::rangeAt($__string, $__delimiter, $__index, $__count, FALSE, $__limit);
- $r[0x01] = array_reverse($r[0x01]);
- $r[0x00] = static::join($r[0x00], $__delimiter);
- $r[0x01] = static::join($r[0x01], $__delimiter);
- $r[0x02] = static::join($r[0x02], $__delimiter);
- return TRUE === $__concat ? static::join($r, $__delimiter) : $r;
- }
- #::
- #:insertAt:
- static function insertAtDir($__string, $__insert, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::insertAt($__string, __str::DIR, $__insert, $__index, $__concat)
- : static::insertAt($__string, __str::DIR, $__insert, $__index, $__concat, $__limit);
- }
- static function insertAtDot($__string, $__insert, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::insertAt($__string, __str::DOT, $__insert, $__index, $__concat)
- : static::insertAt($__string, __str::DOT, $__insert, $__index, $__concat, $__limit);
- }
- static function insertAtEoL($__string, $__insert, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::insertAt($__string, __str::EOL, $__insert, $__index, $__concat)
- : static::insertAt($__string, __str::EOL, $__insert, $__index, $__concat, $__limit);
- }
- static function insertAtMinus($__string, $__insert, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::insertAt($__string, __str::MINUS, $__insert, $__index, $__concat)
- : static::insertAt($__string, __str::MINUS, $__insert, $__index, $__concat, $__limit);
- }
- static function insertAtPath($__string, $__insert, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::insertAt($__string, __str::PATH, $__insert, $__index, $__concat)
- : static::insertAt($__string, __str::PATH, $__insert, $__index, $__concat, $__limit);
- }
- static function insertAtPlus($__string, $__insert, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::insertAt($__string, __str::PLUS, $__insert, $__index, $__concat)
- : static::insertAt($__string, __str::PLUS, $__insert, $__index, $__concat, $__limit);
- }
- static function insertAtSlash($__string, $__insert, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::insertAt($__string, __str::SLASH, $__insert, $__index, $__concat)
- : static::insertAt($__string, __str::SLASH, $__insert, $__index, $__concat, $__limit);
- }
- static function insertAtSpace($__string, $__insert, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::insertAt($__string, __str::SPACE, $__insert, $__index, $__concat)
- : static::insertAt($__string, __str::SPACE, $__insert, $__index, $__concat, $__limit);
- }
- static function insertAtUnderscore($__string, $__insert, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::insertAt($__string, __str::UNDERSCORE, $__insert, $__index, $__concat)
- : static::insertAt($__string, __str::UNDERSCORE, $__insert, $__index, $__concat, $__limit);
- }
- #::
- #:rangeAt:
- static function rangeAtDir($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::rangeAt($__string, __str::DIR, $__index, $__count, $__concat)
- : static::rangeAt($__string, __str::DIR, $__index, $__count, $__concat, $__limit);
- }
- static function rangeAtDot($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::rangeAt($__string, __str::DOT, $__index, $__count, $__concat)
- : static::rangeAt($__string, __str::DOT, $__index, $__count, $__concat, $__limit);
- }
- static function rangeAtEoL($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::rangeAt($__string, __str::EOL, $__index, $__count, $__concat)
- : static::rangeAt($__string, __str::EOL, $__index, $__count, $__concat, $__limit);
- }
- static function rangeAtMinus($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::rangeAt($__string, __str::MINUS, $__index, $__count, $__concat)
- : static::rangeAt($__string, __str::MINUS, $__index, $__count, $__concat, $__limit);
- }
- static function rangeAtPath($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::rangeAt($__string, __str::PATH, $__index, $__count, $__concat)
- : static::rangeAt($__string, __str::PATH, $__index, $__count, $__concat, $__limit);
- }
- static function rangeAtPlus($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::rangeAt($__string, __str::PLUS, $__index, $__count, $__concat)
- : static::rangeAt($__string, __str::PLUS, $__index, $__count, $__concat, $__limit);
- }
- static function rangeAtSlash($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::rangeAt($__string, __str::SLASH, $__index, $__count, $__concat)
- : static::rangeAt($__string, __str::SLASH, $__index, $__count, $__concat, $__limit);
- }
- static function rangeAtSpace($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::rangeAt($__string, __str::SPACE, $__index, $__count, $__concat)
- : static::rangeAt($__string, __str::SPACE, $__index, $__count, $__concat, $__limit);
- }
- static function rangeAtUnderscore($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::rangeAt($__string, __str::UNDERSCORE, $__index, $__count, $__concat)
- : static::rangeAt($__string, __str::UNDERSCORE, $__index, $__count, $__concat, $__limit);
- }
- #::
- #:mergeAt:
- static function mergeAtDir($__string, array $__data, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::mergeAt($__string, __str::DIR, $__data, $__concat)
- : static::mergeAt($__string, __str::DIR, $__data, $__concat, $__limit);
- }
- static function mergeAtDot($__string, array $__data, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::mergeAt($__string, __str::DOT, $__data, $__concat)
- : static::mergeAt($__string, __str::DOT, $__data, $__concat, $__limit);
- }
- static function mergeAtEoL($__string, array $__data, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::mergeAt($__string, __str::EOL, $__data, $__concat)
- : static::mergeAt($__string, __str::EOL, $__data, $__concat, $__limit);
- }
- static function mergeAtMinus($__string, array $__data, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::mergeAt($__string, __str::MINUS, $__data, $__concat)
- : static::mergeAt($__string, __str::MINUS, $__data, $__concat, $__limit);
- }
- static function mergeAtPath($__string, array $__data, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::mergeAt($__string, __str::PATH, $__data, $__concat)
- : static::mergeAt($__string, __str::PATH, $__data, $__concat, $__limit);
- }
- static function mergeAtPlus($__string, array $__data, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::mergeAt($__string, __str::PLUS, $__data, $__concat)
- : static::mergeAt($__string, __str::PLUS, $__data, $__concat, $__limit);
- }
- static function mergeAtSlash($__string, array $__data, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::mergeAt($__string, __str::SLASH, $__data, $__concat)
- : static::mergeAt($__string, __str::SLASH, $__data, $__concat, $__limit);
- }
- static function mergeAtSpace($__string, array $__data, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::mergeAt($__string, __str::SPACE, $__data, $__concat)
- : static::mergeAt($__string, __str::SPACE, $__data, $__concat, $__limit);
- }
- static function mergeAtUnderscore($__string, array $__data, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::mergeAt($__string, __str::UNDERSCORE, $__data, $__concat)
- : static::mergeAt($__string, __str::UNDERSCORE, $__data, $__concat, $__limit);
- }
- #::
- #:removeAt:
- static function removeAtDir($__string, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::removeAt($__string, __str::DIR, $__index, $__concat)
- : static::removeAt($__string, __str::DIR, $__index, $__concat, $__limit);
- }
- static function removeAtDot($__string, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::removeAt($__string, __str::DOT, $__index, $__concat)
- : static::removeAt($__string, __str::DOT, $__index, $__concat, $__limit);
- }
- static function removeAtEoL($__string, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::removeAt($__string, __str::EOL, $__index, $__concat)
- : static::removeAt($__string, __str::EOL, $__index, $__concat, $__limit);
- }
- static function removeAtMinus($__string, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::removeAt($__string, __str::MINUS, $__index, $__concat)
- : static::removeAt($__string, __str::MINUS, $__index, $__concat, $__limit);
- }
- static function removeAtPath($__string, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::removeAt($__string, __str::PATH, $__index, $__concat)
- : static::removeAt($__string, __str::PATH, $__index, $__concat, $__limit);
- }
- static function removeAtPlus($__string, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::removeAt($__string, __str::PLUS, $__index, $__concat)
- : static::removeAt($__string, __str::PLUS, $__index, $__concat, $__limit);
- }
- static function removeAtSlash($__string, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::removeAt($__string, __str::SLASH, $__index, $__concat)
- : static::removeAt($__string, __str::SLASH, $__index, $__concat, $__limit);
- }
- static function removeAtSpace($__string, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::removeAt($__string, __str::SPACE, $__index, $__concat)
- : static::removeAt($__string, __str::SPACE, $__index, $__concat, $__limit);
- }
- static function removeAtUnderscore($__string, $__index, $__concat = TRUE, $__limit = NULL)
- {
- return 0x03 >= func_num_args()
- ? static::removeAt($__string, __str::UNDERSCORE, $__index, $__concat)
- : static::removeAt($__string, __str::UNDERSCORE, $__index, $__concat, $__limit);
- }
- #::
- #:removeRangeAt:
- static function removeRangeAtDir($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::removeRangeAt($__string, __str::DIR, $__index, $__count, $__concat)
- : static::removeRangeAt($__string, __str::DIR, $__index, $__count, $__concat, $__limit);
- }
- static function removeRangeAtDot($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::removeRangeAt($__string, __str::DOT, $__index, $__count, $__concat)
- : static::removeRangeAt($__string, __str::DOT, $__index, $__count, $__concat, $__limit);
- }
- static function removeRangeAtEoL($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::removeRangeAt($__string, __str::EOL, $__index, $__count, $__concat)
- : static::removeRangeAt($__string, __str::EOL, $__index, $__count, $__concat, $__limit);
- }
- static function removeRangeAtMinus($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::removeRangeAt($__string, __str::MINUS, $__index, $__count, $__concat)
- : static::removeRangeAt($__string, __str::MINUS, $__index, $__count, $__concat, $__limit);
- }
- static function removeRangeAtPath($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::removeRangeAt($__string, __str::PATH, $__index, $__count, $__concat)
- : static::removeRangeAt($__string, __str::PATH, $__index, $__count, $__concat, $__limit);
- }
- static function removeRangeAtPlus($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::removeRangeAt($__string, __str::PLUS, $__index, $__count, $__concat)
- : static::removeRangeAt($__string, __str::PLUS, $__index, $__count, $__concat, $__limit);
- }
- static function removeRangeAtSlash($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::removeRangeAt($__string, __str::SLASH, $__index, $__count, $__concat)
- : static::removeRangeAt($__string, __str::SLASH, $__index, $__count, $__concat, $__limit);
- }
- static function removeRangeAtSpace($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::removeRangeAt($__string, __str::SPACE, $__index, $__count, $__concat)
- : static::removeRangeAt($__string, __str::SPACE, $__index, $__count, $__concat, $__limit);
- }
- static function removeRangeAtUnderscore($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::removeRangeAt($__string, __str::UNDERSCORE, $__index, $__count, $__concat)
- : static::removeRangeAt($__string, __str::UNDERSCORE, $__index, $__count, $__concat, $__limit);
- }
- #::
- #:reverseAt:
- static function reverseAtDir($__string, $__concat = TRUE, $__limit = NULL)
- {
- return 0x02 >= func_num_args()
- ? static::reverseAt($__string, __str::DIR, $__concat)
- : static::reverseAt($__string, __str::DIR, $__concat, $__limit);
- }
- static function reverseAtDot($__string, $__concat = TRUE, $__limit = NULL)
- {
- return 0x02 >= func_num_args()
- ? static::reverseAt($__string, __str::DOT, $__concat)
- : static::reverseAt($__string, __str::DOT, $__concat, $__limit);
- }
- static function reverseAtEoL($__string, $__concat = TRUE, $__limit = NULL)
- {
- return 0x02 >= func_num_args()
- ? static::reverseAt($__string, __str::EOL, $__concat)
- : static::reverseAt($__string, __str::EOL, $__concat, $__limit);
- }
- static function reverseAtMinus($__string, $__concat = TRUE, $__limit = NULL)
- {
- return 0x02 >= func_num_args()
- ? static::reverseAt($__string, __str::MINUS, $__concat)
- : static::reverseAt($__string, __str::MINUS, $__concat, $__limit);
- }
- static function reverseAtPath($__string, $__concat = TRUE, $__limit = NULL)
- {
- return 0x02 >= func_num_args()
- ? static::reverseAt($__string, __str::PATH, $__concat)
- : static::reverseAt($__string, __str::PATH, $__concat, $__limit);
- }
- static function reverseAtPlus($__string, $__concat = TRUE, $__limit = NULL)
- {
- return 0x02 >= func_num_args()
- ? static::reverseAt($__string, __str::PLUS, $__concat)
- : static::reverseAt($__string, __str::PLUS, $__concat, $__limit);
- }
- static function reverseAtSlash($__string, $__concat = TRUE, $__limit = NULL)
- {
- return 0x02 >= func_num_args()
- ? static::reverseAt($__string, __str::SLASH, $__concat)
- : static::reverseAt($__string, __str::SLASH, $__concat, $__limit);
- }
- static function reverseAtSpace($__string, $__concat = TRUE, $__limit = NULL)
- {
- return 0x02 >= func_num_args()
- ? static::reverseAt($__string, __str::SPACE, $__concat)
- : static::reverseAt($__string, __str::SPACE, $__concat, $__limit);
- }
- static function reverseAtUnderscore($__string, $__concat = TRUE, $__limit = NULL)
- {
- return 0x02 >= func_num_args()
- ? static::reverseAt($__string, __str::UNDERSCORE, $__concat)
- : static::reverseAt($__string, __str::UNDERSCORE, $__concat, $__limit);
- }
- #::
- #:reverseRangeAt:
- static function reverseRangeAtDir($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::reverseRangeAt($__string, __str::DIR, $__index, $__count, $__concat)
- : static::reverseRangeAt($__string, __str::DIR, $__index, $__count, $__concat, $__limit);
- }
- static function reverseRangeAtDot($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::reverseRangeAt($__string, __str::DOT, $__index, $__count, $__concat)
- : static::reverseRangeAt($__string, __str::DOT, $__index, $__count, $__concat, $__limit);
- }
- static function reverseRangeAtEoL($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::reverseRangeAt($__string, __str::EOL, $__index, $__count, $__concat)
- : static::reverseRangeAt($__string, __str::EOL, $__index, $__count, $__concat, $__limit);
- }
- static function reverseRangeAtMinus($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::reverseRangeAt($__string, __str::MINUS, $__index, $__count, $__concat)
- : static::reverseRangeAt($__string, __str::MINUS, $__index, $__count, $__concat, $__limit);
- }
- static function reverseRangeAtPath($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::reverseRangeAt($__string, __str::PATH, $__index, $__count, $__concat)
- : static::reverseRangeAt($__string, __str::PATH, $__index, $__count, $__concat, $__limit);
- }
- static function reverseRangeAtPlus($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::reverseRangeAt($__string, __str::PLUS, $__index, $__count, $__concat)
- : static::reverseRangeAt($__string, __str::PLUS, $__index, $__count, $__concat, $__limit);
- }
- static function reverseRangeAtSlash($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::reverseRangeAt($__string, __str::SLASH, $__index, $__count, $__concat)
- : static::reverseRangeAt($__string, __str::SLASH, $__index, $__count, $__concat, $__limit);
- }
- static function reverseRangeAtSpace($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::reverseRangeAt($__string, __str::SPACE, $__index, $__count, $__concat)
- : static::reverseRangeAt($__string, __str::SPACE, $__index, $__count, $__concat, $__limit);
- }
- static function reverseRangeAtUnderscore($__string, $__index, $__count, $__concat = TRUE, $__limit = NULL)
- {
- return 0x04 >= func_num_args()
- ? static::reverseRangeAt($__string, __str::UNDERSCORE, $__index, $__count, $__concat)
- : static::reverseRangeAt($__string, __str::UNDERSCORE, $__index, $__count, $__concat, $__limit);
- }
- #::
- #:explode:
- static function explodeDir($__string, $__limit = NULL)
- {
- return 0x01 >= func_num_args()
- ? static::explode($__string, __str::DIR)
- : static::explode($__string, __str::DIR, $__limit);
- }
- static function explodeDot($__string, $__limit = NULL)
- {
- return 0x01 >= func_num_args()
- ? static::explode($__string, __str::DOT)
- : static::explode($__string, __str::DOT, $__limit);
- }
- static function explodeEoL($__string, $__limit = NULL)
- {
- return 0x01 >= func_num_args()
- ? static::explode($__string, __str::EOL)
- : static::explode($__string, __str::EOL, $__limit);
- }
- static function explodeMinus($__string, $__limit = NULL)
- {
- return 0x01 >= func_num_args()
- ? static::explode($__string, __str::MINUS)
- : static::explode($__string, __str::MINUS, $__limit);
- }
- static function explodePath($__string, $__limit = NULL)
- {
- return 0x01 >= func_num_args()
- ? static::explode($__string, __str::PATH)
- : static::explode($__string, __str::PATH, $__limit);
- }
- static function explodePlus($__string, $__limit = NULL)
- {
- return 0x01 >= func_num_args()
- ? static::explode($__string, __str::PLUS)
- : static::explode($__string, __str::PLUS, $__limit);
- }
- static function explodeSlash($__string, $__limit = NULL)
- {
- return 0x01 >= func_num_args()
- ? static::explode($__string, __str::SLASH)
- : static::explode($__string, __str::SLASH, $__limit);
- }
- static function explodeSpace($__string, $__limit = NULL)
- {
- return 0x01 >= func_num_args()
- ? static::explode($__string, __str::SPACE)
- : static::explode($__string, __str::SPACE, $__limit);
- }
- static function explodeUnderscore($__string, $__limit = NULL)
- {
- return 0x01 >= func_num_args()
- ? static::explode($__string, __str::UNDERSCORE)
- : static::explode($__string, __str::UNDERSCORE, $__limit);
- }
- #::
- #:join:
- static function joinDir(array $__data)
- {
- return static::join($__data, __str::DIR);
- }
- static function joinDot(array $__data)
- {
- return static::join($__data, __str::DOT);
- }
- static function joinEoL(array $__data)
- {
- return static::join($__data, __str::EOL);
- }
- static function joinMinus(array $__data)
- {
- return static::join($__data, __str::MINUS);
- }
- static function joinPath(array $__data)
- {
- return static::join($__data, __str::PATH);
- }
- static function joinPlus(array $__data)
- {
- return static::join($__data, __str::PLUS);
- }
- static function joinSlash(array $__data)
- {
- return static::join($__data, __str::SLASH);
- }
- static function joinSpace(array $__data)
- {
- return static::join($__data, __str::SPACE);
- }
- static function joinUnderscore(array $__data)
- {
- return static::join($__data, __str::UNDERSCORE);
- }
- static function joinWords(array $__data, $__beforeLast = NULL)
- {
- if(NULL === $__beforeLast || 0x01 >= count($__data))
- return static::join($__data, __str::COMMA_SPACE);
- $l = array_pop($__data);
- return static::concatSpace(static::join($__data, __str::COMMA_SPACE), $__beforeLast, $l);
- }
- #::
- #:concat:
- static function concatDir($__stringN)
- {
- return static::joinDir(func_get_args());
- }
- static function concatDot($__stringN)
- {
- return static::joinDot(func_get_args());
- }
- static function concatEoL($__stringN)
- {
- return static::joinEoL(func_get_args());
- }
- static function concatPath($__stringN)
- {
- return static::joinPath(func_get_args());
- }
- static function concatPlus($__stringN)
- {
- return static::joinPlus(func_get_args());
- }
- static function concatSlash($__stringN)
- {
- return static::joinSlash(func_get_args());
- }
- static function concatSpace($__stringN)
- {
- return static::joinSpace(func_get_args());
- }
- static function concatUnderscore($__stringN)
- {
- return static::joinUnderscore(func_get_args());
- }
- #::
- #:pad:
- static function lPad($__string, $__length, $__delimiter)
- {
- return static::pad($__string, $__length, $__delimiter, STR_PAD_LEFT);
- }
- static function lPadDot($__string, $__length)
- {
- return static::lPad($__string, $__length, __str::DOT);
- }
- static function lPadSpace($__string, $__length)
- {
- return static::lPad($__string, $__length, __str::SPACE);
- }
- static function rPad($__string, $__length, $__delimiter)
- {
- return static::pad($__string, $__length, $__delimiter, STR_PAD_RIGHT);
- }
- static function rPadDot($__string, $__length)
- {
- return static::rPad($__string, $__length, __str::DOT);
- }
- static function rPadSpace($__string, $__length)
- {
- return static::rPad($__string, $__length, __str::SPACE);
- }
- #::
- #:repeat:
- static function repeatDot($__length)
- {
- return static::repeat(__str::DOT, $__length);
- }
- static function repeatEoL($__length)
- {
- return static::repeat(__str::EOL, $__length);
- }
- static function repeatSpace($__length)
- {
- return static::repeat(__str::SPACE, $__length);
- }
- static function repeatTab($__length)
- {
- return static::repeat(chr(__chr::TAB), $__length);
- }
- #::
- #:chrOffset:
- static function lChrOffset($__string, $__char, $__until = 0x01)
- {
- return static::__chrOffset($__string, $__char, FALSE, $__until);
- }
- static function rChrOffset($__string, $__char, $__until = 0x01)
- {
- return static::__chrOffset($__string, $__char, TRUE, $__until);
- }
- protected function __chrOffset($__string, $__char, $__reverse, $__until = 0x01)
- {
- $i = 0x00;
- $l = 0x00;
- $r = TRUE === $__reverse
- ? static::reverse($__string, FALSE)
- : static::split($__string, FALSE);
- foreach($r as $c)
- {
- if($c === $__char
- && ++$i === $__until)
- return $l;
- $l++;
- }
- return FALSE;
- }
- #::
- #:sub:
- static function lSub($__string, $__char, $__until = 0x01, $__length = NULL)
- {
- if(FALSE === ($o = static::lChrOffset($__string, $__char, $__until)))
- return NULL;
- return 0x03 >= func_num_args()
- ? static::sub(static::sub($__string, 0, $o), -$o)
- : static::sub(static::sub($__string, 0, $o), -$o, $__length);
- }
- static function rSub($__string, $__char, $__until = 0x01, $__length = NULL)
- {
- if(FALSE === ($o = static::rChrOffset($__string, $__char, $__until)))
- return NULL;
- return 0x03 >= func_num_args()
- ? static::sub($__string, -$o)
- : static::sub($__string, -$o, $__length);
- }
- #::
- #:is:
- static function lIs($__string, $__search)
- {
- return static::sub($__string, 0x00, static::len($__search)) === $__search;
- }
- static function rIs($__string, $__search)
- {
- return static::sub($__string, -static::len($__search)) === $__search;
- }
- #::
- #:count:
- static function lCount($__string, $__search)
- {
- $c = 0x00;
- $s = $__string;
- while(static::lIs($s, $__search) && ++$c)
- $s = static::lCut($s, $__search, FALSE);
- return $c;
- }
- static function rCount($__string, $__search)
- {
- $c = 0x00;
- $s = $__string;
- while(static::rIs($s, $__search) && ++$c)
- $s = static::rCut($s, $__search, FALSE);
- return $c;
- }
- #::
- #:cut:
- static function lCut($__string, $__search, $__deep = FALSE)
- {
- if(is_array($__search))
- {
- foreach($__search as $s)
- $__string = static::lCut($__string, $s, $__deep);
- return $__string;
- }
- if(FALSE === $__deep || 0x01 === $__deep)
- return FALSE === static::lIs($__string, $__search)
- ? $__string
- : static::sub($__string, static::len($__search));
- $m = 0x00;
- $d = (int) $__deep;
- while(static::lIs($__string, $__search))
- {
- if(TRUE !== $__deep && $m++ === $d)
- break;
- $__string = static::lCut($__string, $__search, FALSE);
- }
- return $__string;
- }
- static function rCut($__string, $__search, $__deep = FALSE)
- {
- if(is_array($__search))
- {
- foreach($__search as $s)
- $__string = static::rCut($__string, $s, $__deep);
- return $__string;
- }
- if(FALSE === $__deep || 0x01 === $__deep)
- return FALSE === static::rIs($__string, $__search)
- ? $__string
- : static::sub($__string, 0x00, -static::len($__search));
- $m = 0x00;
- $d = (int) $__deep;
- while(static::rIs($__string, $__search))
- {
- if(TRUE !== $__deep && $m++ === $d)
- break;
- $__string = static::rCut($__string, $__search, FALSE);
- }
- return $__string;
- }
- #::
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement