PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Libraries/Sabberworm/CSS/src/Value/CSSString.php +51 -61 10.2.2 → 11.1.0 View file →
@@ -1,105 +1,95 @@
1 1 <?php
2 2
3 -namespace Sabberworm\CSS\Value;
3 +declare(strict_types=1);
4 4
5 -use Sabberworm\CSS\OutputFormat;
6 -use Sabberworm\CSS\Parsing\ParserState;
7 -use Sabberworm\CSS\Parsing\SourceException;
8 -use Sabberworm\CSS\Parsing\UnexpectedEOFException;
9 -use Sabberworm\CSS\Parsing\UnexpectedTokenException;
5 +namespace AcyMailing\Libraries\Sabberworm\CSS\Value;
10 6
7 +use AcyMailing\Libraries\Sabberworm\CSS\OutputFormat;
8 +use AcyMailing\Libraries\Sabberworm\CSS\Parsing\ParserState;
9 +use AcyMailing\Libraries\Sabberworm\CSS\Parsing\SourceException;
10 +use AcyMailing\Libraries\Sabberworm\CSS\Parsing\UnexpectedEOFException;
11 +use AcyMailing\Libraries\Sabberworm\CSS\Parsing\UnexpectedTokenException;
12 +
13 +/**
14 + * This class is a wrapper for quoted strings to distinguish them from keywords.
15 + *
16 + * `CSSString`s always output with double quotes.
17 + */
11 18 class CSSString extends PrimitiveValue
12 19 {
13 20 /**
14 21 * @var string
15 22 */
16 - private $sString;
23 + private $string;
17 24
18 25 /**
19 - * @param string $sString
20 - * @param int $iLineNo
26 + * @param int<1, max>|null $lineNumber
21 27 */
22 - public function __construct($sString, $iLineNo = 0)
28 + public function __construct(string $string, ?int $lineNumber = null)
23 29 {
24 - $this->sString = $sString;
25 - parent::__construct($iLineNo);
30 + $this->string = $string;
31 + parent::__construct($lineNumber);
26 32 }
27 33
28 34 /**
29 - * @return CSSString
30 - *
31 35 * @throws SourceException
32 36 * @throws UnexpectedEOFException
33 37 * @throws UnexpectedTokenException
38 + *
39 + * @internal since V8.8.0
34 40 */
35 - public static function parse(ParserState $oParserState)
41 + public static function parse(ParserState $parserState): CSSString
36 42 {
37 - $sBegin = $oParserState->peek();
38 - $sQuote = null;
39 - if ($sBegin === "'") {
40 - $sQuote = "'";
41 - } elseif ($sBegin === '"') {
42 - $sQuote = '"';
43 + $begin = $parserState->peek();
44 + $quote = null;
45 + if ($begin === "'") {
46 + $quote = "'";
47 + } elseif ($begin === '"') {
48 + $quote = '"';
43 49 }
44 - if ($sQuote !== null) {
45 - $oParserState->consume($sQuote);
50 + if ($quote !== null) {
51 + $parserState->consume($quote);
46 52 }
47 - $sResult = "";
48 - $sContent = null;
49 - if ($sQuote === null) {
53 + $result = '';
54 + $content = null;
55 + if ($quote === null) {
50 56 // Unquoted strings end in whitespace or with braces, brackets, parentheses
51 - while (!preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) {
52 - $sResult .= $oParserState->parseCharacter(false);
57 + while (\preg_match('/[\\s{}()<>\\[\\]]/isu', $parserState->peek()) !== 1) {
58 + $result .= $parserState->parseCharacter(false);
53 59 }
54 60 } else {
55 - while (!$oParserState->comes($sQuote)) {
56 - $sContent = $oParserState->parseCharacter(false);
57 - if ($sContent === null) {
61 + while (!$parserState->comes($quote)) {
62 + $content = $parserState->parseCharacter(false);
63 + if ($content === null) {
58 64 throw new SourceException(
59 - "Non-well-formed quoted string {$oParserState->peek(3)}",
60 - $oParserState->currentLine()
65 + "Non-well-formed quoted string {$parserState->peek(3)}",
66 + $parserState->currentLine()
61 67 );
62 68 }
63 - $sResult .= $sContent;
69 + $result .= $content;
64 70 }
65 - $oParserState->consume($sQuote);
71 + $parserState->consume($quote);
66 72 }
67 - return new CSSString($sResult, $oParserState->currentLine());
73 + return new CSSString($result, $parserState->currentLine());
68 74 }
69 75
70 - /**
71 - * @param string $sString
72 - *
73 - * @return void
74 - */
75 - public function setString($sString)
76 + public function setString(string $string): void
76 77 {
77 - $this->sString = $sString;
78 + $this->string = $string;
78 79 }
79 80
80 - /**
81 - * @return string
82 - */
83 - public function getString()
81 + public function getString(): string
84 82 {
85 - return $this->sString;
83 + return $this->string;
86 84 }
87 85
88 86 /**
89 - * @return string
87 + * @return non-empty-string
90 88 */
91 - public function __toString()
89 + public function render(OutputFormat $outputFormat): string
92 90 {
93 - return $this->render(new OutputFormat());
94 - }
95 -
96 - /**
97 - * @return string
98 - */
99 - public function render(OutputFormat $oOutputFormat)
100 - {
101 - $sString = addslashes($this->sString);
102 - $sString = str_replace("\n", '\A', $sString);
103 - return $oOutputFormat->getStringQuotingType() . $sString . $oOutputFormat->getStringQuotingType();
91 + $string = \addslashes($this->string);
92 + $string = \str_replace("\n", '\\A', $string);
93 + return $outputFormat->getStringQuotingType() . $string . $outputFormat->getStringQuotingType();
104 94 }
105 95 }