PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / vendor / sabberworm / php-css-parser / src / Value / CSSString.php

CSSString.php in Yatra – Travel Booking & Tour Operator Software trunk, at vendor/sabberworm/php-css-parser/src/Value/CSSString.php

117 lines 3.0 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 /**
12 * This class is a wrapper for quoted strings to distinguish them from keywords.
13 *
14 * `CSSString`s always output with double quotes.
15 */
16 class CSSString extends PrimitiveValue
17 {
18 /**
19 * @var string
20 */
21 private $sString;
22
23 /**
24 * @param string $sString
25 * @param int $iLineNo
26 */
27 public function __construct($sString, $iLineNo = 0)
28 {
29 $this->sString = $sString;
30 parent::__construct($iLineNo);
31 }
32
33 /**
34 * @return CSSString
35 *
36 * @throws SourceException
37 * @throws UnexpectedEOFException
38 * @throws UnexpectedTokenException
39 *
40 * @internal since V8.8.0
41 */
42 public static function parse(ParserState $oParserState)
43 {
44 $sBegin = $oParserState->peek();
45 $sQuote = null;
46 if ($sBegin === "'") {
47 $sQuote = "'";
48 } elseif ($sBegin === '"') {
49 $sQuote = '"';
50 }
51 if ($sQuote !== null) {
52 $oParserState->consume($sQuote);
53 }
54 $sResult = "";
55 $sContent = null;
56 if ($sQuote === null) {
57 // Unquoted strings end in whitespace or with braces, brackets, parentheses
58 while (!preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) {
59 $sResult .= $oParserState->parseCharacter(false);
60 }
61 } else {
62 while (!$oParserState->comes($sQuote)) {
63 $sContent = $oParserState->parseCharacter(false);
64 if ($sContent === null) {
65 throw new SourceException(
66 "Non-well-formed quoted string {$oParserState->peek(3)}",
67 $oParserState->currentLine()
68 );
69 }
70 $sResult .= $sContent;
71 }
72 $oParserState->consume($sQuote);
73 }
74 return new CSSString($sResult, $oParserState->currentLine());
75 }
76
77 /**
78 * @param string $sString
79 *
80 * @return void
81 */
82 public function setString($sString)
83 {
84 $this->sString = $sString;
85 }
86
87 /**
88 * @return string
89 */
90 public function getString()
91 {
92 return $this->sString;
93 }
94
95 /**
96 * @return string
97 *
98 * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
99 */
100 public function __toString()
101 {
102 return $this->render(new OutputFormat());
103 }
104
105 /**
106 * @param OutputFormat|null $oOutputFormat
107 *
108 * @return string
109 */
110 public function render($oOutputFormat)
111 {
112 $sString = addslashes($this->sString);
113 $sString = str_replace("\n", '\A', $sString);
114 return $oOutputFormat->getStringQuotingType() . $sString . $oOutputFormat->getStringQuotingType();
115 }
116 }
117