mirror of
https://github.com/wallabag/wallabag.git
synced 2025-07-12 16:58:37 +00:00
use directly MOBIClass
This commit is contained in:
parent
c70bfefc68
commit
fb9df0c269
47 changed files with 309 additions and 1551 deletions
83
inc/3rdparty/libraries/MOBIClass/FileString.php
vendored
Normal file
83
inc/3rdparty/libraries/MOBIClass/FileString.php
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Description of FileString
|
||||
*
|
||||
* @author Sander
|
||||
*/
|
||||
class FileString extends FileObject {
|
||||
private $forcedLength;
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* Make a string to be stored in a file
|
||||
* @param string|int $first Optional, if it is a string, it will be the contents,
|
||||
* if it is a number, it will set the forced length.
|
||||
* @param int $second Optional, will set the forced length. Can only be used when the
|
||||
* first argument is contents.
|
||||
*/
|
||||
public function __construct($first = null, $second = null){
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue