From fb9df0c269f36703909b8b259abbdbed29881ecd Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 21:56:04 +0200 Subject: use directly MOBIClass --- inc/3rdparty/libraries/MOBIClass/FileString.php | 83 +++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 inc/3rdparty/libraries/MOBIClass/FileString.php (limited to 'inc/3rdparty/libraries/MOBIClass/FileString.php') diff --git a/inc/3rdparty/libraries/MOBIClass/FileString.php b/inc/3rdparty/libraries/MOBIClass/FileString.php new file mode 100644 index 00000000..16e906a6 --- /dev/null +++ b/inc/3rdparty/libraries/MOBIClass/FileString.php @@ -0,0 +1,83 @@ +forcedLength = -1; + $this->data = ""; + + if($second != null){ + $this->data = $first; + $this->forcedLength = $second; + }else if($first != null){ + if(is_string($first)){ + $this->data = $first; + }else{ + $this->forcedLength = $first; + } + } + } + + public function getByteLength(){ + return $this->getLength(); + } + + public function getLength(){ + if($this->forcedLength >= 0){ + return $this->forcedLength; + } + return strlen($this->data); + } + + public function get(){ + return $this->data; + } + + public function set($value){ + $this->data = $value; + } + + public function serialize() { + $output = $this->data; + $curLength = strlen($output); + + if($this->forcedLength >= 0){ + if($this->forcedLength > $curLength){ + return str_pad($output, $this->forcedLength, "\0", STR_PAD_RIGHT); + }elseif($this->forcedLength == $curLength){ + return $output; + }else{ + return substr($output, 0, $this->forcedLength); + } + } + return $output; + } + + public function unserialize($data) { + __construct($data); + } + + public function __toString(){ + $out = "FileString"; + if($this->forcedLength >= 0){ + $out .= " ".$this->forcedLength; + } + $out .= ": {\"".str_replace(array(" ", "\0"), " ", $this->serialize())."\"}"; + return $out; + } +} +?> -- cgit v1.2.3