-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBFString.php
More file actions
56 lines (45 loc) · 1.32 KB
/
BFString.php
File metadata and controls
56 lines (45 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace com\bubblefoundry\collections;
class BFString extends BFArray {
function __construct($str) {
if ($str instanceof BFArray || is_array($str)) {
$arr = $str;
}
else {
$arr = array();
for ($k = 0; $k < strlen($str); $k++) {
$arr[] = substr($str, $k, 1);
}
}
parent::__construct($arr);
}
function toString() {
return $this->implode("");
}
function toUpperCase() {
return new BFString($this->map(function ($c) { return ucfirst($c); })->toArray());
}
function toLowerCase() {
return new BFString($this->map(function ($c) { return strtolower($c); })->toArray());
}
function replace($search, $replace) {
return new BFString(str_replace($search, $replace, $this->toString()));
}
function substr($start, $length = NULL) {
if (is_null($length)) {
return new BFString(substr($this->toString(), $start));
} else {
return new BFString(substr($this->toString(), $start, $length));
}
}
function position($needle, $offset = NULL) {
return strpos($this->toString(), $needle, $offset);
}
function contains($needle) {
return is_numeric($this->position($needle)) ? true : false;
}
function explode($sep, $limit = NULL) {
return new BFArray(explode($sep, $this->toString(), $limit));
}
}
?>