From fd71028615ea3404fa125a321f813e9c8848f899 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 24 Jun 2024 03:35:08 +0300 Subject: [PATCH] implement Quote support --- src/Document.php | 11 +++++++++++ src/Entity/Quote.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/Parser/Quote.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 src/Entity/Quote.php create mode 100644 src/Parser/Quote.php diff --git a/src/Document.php b/src/Document.php index 0fdf23b..f75a6be 100644 --- a/src/Document.php +++ b/src/Document.php @@ -60,6 +60,17 @@ class Document break; + // Quote + case Parser\Quote::match($line): + + $this->_entities[] = new Entity\Quote( + Parser\Quote::getText( + $line + ) + ); + + break; + // Plain default: diff --git a/src/Entity/Quote.php b/src/Entity/Quote.php new file mode 100644 index 0000000..4adef6a --- /dev/null +++ b/src/Entity/Quote.php @@ -0,0 +1,44 @@ +'; + + private ?string $_text; + + public function __construct( + ?string $text = null + ) { + $this->setText( + $text + ); + } + + public function setText( + ?string $text + ): void + { + if ($text) + { + $text = trim( + $text + ); + } + + $this->_text = $text; + } + + public function Text(): ?string + { + return $this->_text; + } + + public function toString(): string + { + return self::TAG . ' ' . $this->_text; + } +} \ No newline at end of file diff --git a/src/Parser/Quote.php b/src/Parser/Quote.php new file mode 100644 index 0000000..507be4d --- /dev/null +++ b/src/Parser/Quote.php @@ -0,0 +1,44 @@ +\s*(?.*)$/m', + $line, + $matches + ); + } + + public static function getText( + string $line + ): ?string + { + $matches = []; + + if (self::match($line, $matches)) + { + if (isset($matches['text'])) + { + $text = trim( + $matches['text'] + ); + + if ($text) + { + return $text; + } + } + } + + return null; + } +} \ No newline at end of file