PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.1.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.1.4
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
acymailing / back / Libraries / Sabberworm / CSS / src / Value / CSSString.php

CSSString.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.1.4, at back/Libraries/Sabberworm/CSS/src/Value/CSSString.php

106 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sabberworm\CSS\Value;
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;
10
11 class CSSString extends PrimitiveValue
12 {
13 /**
14 * @var string
15 */
16 private $sString;
17
18 /**
19 * @param string $sString
20 * @param int $iLineNo
21 */
22 public function __construct($sString, $iLineNo = 0)
23 {
24 $this->sString = $sString;
25 parent::__construct($iLineNo);
26 }
27
28 /**
29 * @return CSSString
30 *
31 * @throws SourceException
32 * @throws UnexpectedEOFException
33 * @throws UnexpectedTokenException
34 */
35 public static function parse(ParserState $oParserState)
36 {
37 $sBegin = $oParserState->peek();
38 $sQuote = null;
39 if ($sBegin === "'") {
40 $sQuote = "'";
41 } elseif ($sBegin === '"') {
42 $sQuote = '"';
43 }
44 if ($sQuote !== null) {
45 $oParserState->consume($sQuote);
46 }
47 $sResult = "";
48 $sContent = null;
49 if ($sQuote === null) {
50 // Unquoted strings end in whitespace or with braces, brackets, parentheses
51 while (!preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) {
52 $sResult .= $oParserState->parseCharacter(false);
53 }
54 } else {
55 while (!$oParserState->comes($sQuote)) {
56 $sContent = $oParserState->parseCharacter(false);
57 if ($sContent === null) {
58 throw new SourceException(
59 "Non-well-formed quoted string {$oParserState->peek(3)}",
60 $oParserState->currentLine()
61 );
62 }
63 $sResult .= $sContent;
64 }
65 $oParserState->consume($sQuote);
66 }
67 return new CSSString($sResult, $oParserState->currentLine());
68 }
69
70 /**
71 * @param string $sString
72 *
73 * @return void
74 */
75 public function setString($sString)
76 {
77 $this->sString = $sString;
78 }
79
80 /**
81 * @return string
82 */
83 public function getString()
84 {
85 return $this->sString;
86 }
87
88 /**
89 * @return string
90 */
91 public function __toString()
92 {
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();
104 }
105 }
106