]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/MOBIClass/FileString.php
4 * Description of FileString
8 class FileString
extends FileObject
{
13 * Make a string to be stored in a file
14 * @param string|int $first Optional, if it is a string, it will be the contents,
15 * if it is a number, it will set the forced length.
16 * @param int $second Optional, will set the forced length. Can only be used when the
17 * first argument is contents.
19 public function __construct($first = null, $second = null){
20 $this->forcedLength
= -1;
25 $this->forcedLength
= $second;
26 }else if($first != null){
27 if(is_string($first)){
30 $this->forcedLength
= $first;
35 public function getByteLength(){
36 return $this->getLength();
39 public function getLength(){
40 if($this->forcedLength
>= 0){
41 return $this->forcedLength
;
43 return strlen($this->data
);
46 public function get(){
50 public function set($value){
54 public function serialize() {
55 $output = $this->data
;
56 $curLength = strlen($output);
58 if($this->forcedLength
>= 0){
59 if($this->forcedLength
> $curLength){
60 return str_pad($output, $this->forcedLength
, "\0", STR_PAD_RIGHT
);
61 }elseif($this->forcedLength
== $curLength){
64 return substr($output, 0, $this->forcedLength
);
70 public function unserialize($data) {
74 public function __toString(){
76 if($this->forcedLength
>= 0){
77 $out .= " ".$this->forcedLength
;
79 $out .= ": {\"".str_replace(array(" ", "\0"), " ", $this->serialize())."\"}";