mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Add Excerpt class
This commit is contained in:
parent
7ef8b30043
commit
dcc5ea0c9b
80
src/Parsing/Excerpt.php
Normal file
80
src/Parsing/Excerpt.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Erusev\Parsedown\Parsing;
|
||||||
|
|
||||||
|
final class Excerpt
|
||||||
|
{
|
||||||
|
/** @var string */
|
||||||
|
private $context;
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
|
private $offset;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $context
|
||||||
|
* @param int $offset
|
||||||
|
*/
|
||||||
|
public function __construct($context, $offset)
|
||||||
|
{
|
||||||
|
$this->context = $context;
|
||||||
|
$this->offset = $offset;
|
||||||
|
$this->text = \substr($context, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $mask
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function pushingOffsetTo($mask)
|
||||||
|
{
|
||||||
|
return $this->addingToOffset(\strcspn($this->text, $mask));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $offset
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function choppingFromOffset($offset)
|
||||||
|
{
|
||||||
|
return new self(\substr($this->context, $offset), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $offset
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function choppingUpToOffset($offset)
|
||||||
|
{
|
||||||
|
return new self(\substr($this->context, 0, $offset), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $offsetIncrement
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function addingToOffset($offsetIncrement)
|
||||||
|
{
|
||||||
|
return new self($this->context, $this->offset + $offsetIncrement);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return string */
|
||||||
|
public function context()
|
||||||
|
{
|
||||||
|
return $this->context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return int */
|
||||||
|
public function offset()
|
||||||
|
{
|
||||||
|
return $this->offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return string */
|
||||||
|
public function text()
|
||||||
|
{
|
||||||
|
return $this->text;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user