All pastes #500734 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-05-21 18:17 UTC
rendered paste body
class String 
{
     public $string = "";
	 
     function __construct( $string )
	 {
	      $this->string = $string;    
	 }
	 
	 public function append( $string )
	 {
	      $this->string .= $string;
	 }
	 
	 public function toLowerCase()
	 {
	      $this->string = strtolower( $this->string );
	 }
	 
	 public function toUpperCase()
	 {
	      $this->string = strtoupper( $this->string );
	 }
	 
	 public function charAt( $ind )
	 {
	      return $this->string{(int)$ind};
	 }
	 
	 public function equals( $string )
	 {
	      return ($this->string === $string);
	 }
	 
	 public function equalsIgnoreCase( $string )
	 {
	      return (strtolower( $this->string ) === strtolower( $string ));
	 }
	 
	 public function indexOf( $char )
	 {
	      $result = strpos($this->string, $char);
		  return !$result ? -1 : $result;
	 }
	 
	 public function endsWith( $string )
	 {
	      return preg_match("/" . preg_quote($string) . "$/", $this->string);
	 }
	 
	 public function startsWith( $string )
	 {
	      return preg_match("/^" . preg_quote($string) . "/", $this->string);
	 }
	 
	 public function lenght()
	 {
	      return strlen($this->string);
	 }
	 
	 public function replace( $char, $rep )
	 {
	      $this->string = preg_replace("/" . $char{0} . "/", $resp{0}, $this->string);
	 }
	 
	 public function trim()
	 {
	      $this->string = trim( $this->string );
	 }
	 
	 public function substring( $beginIndex, $endIndex )
	 {
	      return substr( $this->string, $beginIndex, $endIndex );
	 }	 
	 
	 public function lastIndexOf( $char )
	 {
	      $strTmp = "";
		  $len = strlen($this->string);
	      for( $i = $len; $i >= 0; $i--)
		     $strTmp .= $this->string{$i};
		  
		  $pos = strpos($strTmp, $char{0});
		  
		  $pos = ($len - $pos);
		  	 
		  return !$pos ? -1 : $pos;	 
	 }	 
	 
	 public function regionMatches( $ignoreCase,
                                    $toffset,
                                    $string,
                                    $ooffset,
                                    $len )
	 {
	      $strTmp = substr($this->string, $toffset, $len);
	      $string = substr($string, $ooffset, $len);
		  $re     = substr_compare( $strTmp, $string, $ooffset, $len, $ignoreCase ); 
		  
		  return $re === 0 ? true : false;
	 }
	 
	 function __call( $meth, $args ) 
	 { 
	      trigger_error( "Metodo no implementado: " . $meth, E_USER_ERROR ); 
	 }
}