phpircbot2/modules/blockstring.class.php

78 lines
1.9 KiB
PHP
Raw Normal View History

2010-11-21 23:13:54 +01:00
<?php
/*****************************
* Blockstring Class by JPT *
* http://jpt.de.tf *
* to be used as a buffer *
*****************************/
class blockstring{
public $endl;
private $datapool;
function __construct($endl){
$this -> datapool = "";
$this -> endl = $endl;
}
public function addData($data){
$this -> datapool .= $data.$this -> endl; //We add the endl to the end of each block of data due to some cutting issues..
}
public function isFull(){
return (trim($this -> datapool) != "") ? true : false;
}
public function gotLine(){
return ($this -> isFull() && (preg_match("/".$this -> endl."/", $this -> datapool))) ? true : false;
}
public function getLineArray(){
if(!$this -> isFull()) return false;
$pool = $this -> datapool; //Copy our original pool
$lines = explode($this -> endl, $pool); //explode by endline...
unset($pool);
//clean up all lines
foreach($lines as $key => $line){
$line = $this -> stripLine($line);
if(trim($line) != "") $lines[$key] = $line;
}
return $lines;
}
public function getNextLine(){
if(!$this -> gotLine()) return false;
$expl = explode($this -> endl, $this -> datapool); //explode by endline...
$line = $expl[0]; //...to get next line from datapool
//Kill the fetched line
unset($expl[0]);
$this -> datapool = implode($this -> endl, $expl);
$line = $this -> stripLine($line); //clean up gained line
if($line == "") return $this -> getNextLine();
return $line;
}
public function countLines(){
$count = count($this -> getLineArray());
return $count;
}
public function stripLine($line){
$replace = array("\r","\n","\0");
$line = str_replace($replace,"",$line);
$line = trim($line);
return $line;
}
public function clear(){
unset($this -> datapool);
$this -> datapool = "";
}
function __destruct(){
unset($this -> datapool);
}
}
?>