Permalink
Browse files

new commit udpated Wed Sep 26 16:08:11 GMT 2012

  • Loading branch information...
1 parent 33fbb5f commit 36d9e42ec326b9e0dab774ef5969804afa4fb66c @Mparaiso committed Sep 26, 2012
Showing with 42 additions and 11 deletions.
  1. +28 −11 String/String.php
  2. +14 −0 tests/String/StringTest.php
View
39 String/String.php
@@ -24,8 +24,7 @@ function _concat($value){
function _match($pattern){
$result = array();
preg_match_all($pattern, $this->value, $result);
- return $result;
-
+ return $result[0];
}
/**
@@ -44,13 +43,13 @@ function _charCodeAt($position){
* alues are replaced.
*/
function _replace($pattern,$replacement){
- $result= @preg_replace($pattern, $replacement, $this->value);
- if($result==null && $replacement!=null){
- return str_replace($pattern, $replacement, $this->value);
- }else{
- return $result;
- }
- return $this->value;
+ $result= @preg_replace($pattern, $replacement, $this->value);
+ if($result==null && $replacement!=null){
+ return str_replace($pattern, $replacement, $this->value);
+ }else{
+ return $result;
+ }
+ return $this->value;
}
/**
@@ -134,6 +133,12 @@ function _indexOf($searchValue,$start=0){
}
}
+ // function _lastIndexOf($search){
+ // $index = strpos(strrev($this->value), strrev($search));
+ // $index = strlen($this->value) - strlen($index) - $index -1;
+ // return $index;
+ // }
+
/**
* Returns the calling string value converted to lower case.
*/
@@ -151,11 +156,23 @@ function _toUpperCase()
/**
* Removes whitespace from both ends of the string.
*/
- function _trim()
- {
+ function _trim(){
return new String(trim($this));
}
+ function _trimLeft(){
+ return new String(ltrim($this->value));
+ }
+
+ function _trimRight(){
+ return new String(rtrim($this->value));
+ }
+
+ function reverse(){
+ return new String(strrev($this->value));
+ }
+
+
/**
* returns the value of the string
*/
View
14 tests/String/StringTest.php
@@ -36,6 +36,20 @@ function testReplace(){
}
+ // function testLastIndexOf(){
+ // $string=new String("it's cool cool cool");
+ // $this->assertEquals(15,$string->lastIndexOf("co"));
+ // $this->assertEquals(0,$string->lastIndexOf("it's "));
+ // }
+
+ function testMatch(){
+ $string = new String("this is a string");
+ $this->assertEquals(array("b","c","d"),array("b","c","d")); // make sure assertEquals can compare 2 arrays
+ $this->assertEquals(array("is","is"),$string->match("/is/"));
+ #$this->assertEquals(array(array("is","is")),$string->match("is"));
+ }
+
+
function testSearch(){
$string = new String("galaxy");
$this->assertEquals(4,$string->search("/xy/"));

0 comments on commit 36d9e42

Please sign in to comment.