1
0
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:
Aidan Woods 2019-01-20 02:10:22 +00:00
parent 7ef8b30043
commit dcc5ea0c9b
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

80
src/Parsing/Excerpt.php Normal file
View 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;
}
}