Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed Parsed to Root

  • Loading branch information...
commit 30d77d1fc7fbc9c5d7037be5956b0c421a416fad 1 parent 4d410cc
@JakubOnderka authored
View
1  lib/CSSTidy.php
@@ -34,7 +34,6 @@
require_once __DIR__ . '/Container.php';
require_once __DIR__ . '/Template.php';
require_once __DIR__ . '/Configuration.php';
-require_once __DIR__ . '/elements/Parsed.php';
require_once __DIR__ . '/Output.php';
/**
View
10 lib/Output.php
@@ -77,7 +77,7 @@ class Output
/** @var Logger */
protected $logger;
- /** @var Parsed */
+ /** @var Root */
protected $parsed;
/** @var array */
@@ -87,9 +87,9 @@ class Output
* @param Configuration $configuration
* @param Logger $logger
* @param string $inputCss
- * @param Parsed $parsed
+ * @param Root $parsed
*/
- public function __construct(Configuration $configuration, Logger $logger, $inputCss, Parsed $parsed)
+ public function __construct(Configuration $configuration, Logger $logger, $inputCss, Root $parsed)
{
$this->configuration = $configuration;
$this->logger = $logger;
@@ -411,7 +411,7 @@ protected function blockToTokens(Block $block, $sortSelectors = false, $sortProp
if ($block instanceof Selector) {
$this->addToken(self::SEL_START, $block->getName());
- } else if ($block instanceof AtBlock && !$block instanceof Parsed) {
+ } else if ($block instanceof AtBlock && !$block instanceof Root) {
$this->addToken(self::AT_START, $block->getName());
}
@@ -438,7 +438,7 @@ protected function blockToTokens(Block $block, $sortSelectors = false, $sortProp
if ($block instanceof Selector) {
$this->addToken(self::SEL_END);
- } else if ($block instanceof AtBlock && !$block instanceof Parsed) {
+ } else if ($block instanceof AtBlock && !$block instanceof Root) {
$this->addToken(self::AT_END);
}
}
View
32 lib/Parser.php
@@ -1,6 +1,8 @@
<?php
namespace CSSTidy;
+require_once __DIR__ . '/elements/Root.php';
+
class Parser
{
/**
@@ -250,12 +252,10 @@ public function __construct(Logger $logger, $discardInvalidProperties, $cssLevel
/**
* @param $string
- * @return Parsed
+ * @return Root
*/
public function parse($string)
{
- $parsed = new Parsed;
-
// Normalize new line characters
$string = str_replace(array("\r\n", "\r"), array("\n", "\n"), $string) . ' ';
@@ -276,7 +276,9 @@ public function parse($string)
*/
$status = 'is';
$subValues = $from = $selectorSeparate = array();
- $stack = array($parsed);
+
+ $root = new Root;
+ $stack = array($root);
for ($i = 0, $size = strlen($string); $i < $size; $i++) {
$current = $string{$i};
@@ -403,12 +405,15 @@ public function parse($string)
$subValue = '';
}
- // Remove right spaces added by Block::addProperty
- $valid = $this->propertyIsValid(rtrim($property));
+ $valid = $this->propertyIsValid($property);
if ($valid || !$this->discardInvalidProperties) {
end($stack)->addProperty(new Property($property, $subValues, $this->currentLine));
} else {
- $this->logger->log("Removed invalid property: $property", Logger::WARNING, $this->currentLine);
+ $this->logger->log(
+ "Removed invalid property: $property",
+ Logger::WARNING,
+ $this->currentLine
+ );
}
if (!$valid && !$this->discardInvalidProperties) {
$this->logger->log(
@@ -558,7 +563,7 @@ public function parse($string)
}
}
- return $parsed;
+ return $root;
}
/**
@@ -583,25 +588,26 @@ protected function setSubSelectors(Selector $selector, array $selectorSeparate)
}
/**
- * @todo If comment is to end of file
* @param string $string
* @param int $i
* @return string
*/
protected function parseComment($string, &$i)
{
- $i += 2; // /*
+ $i += 2; // Skip /* characters
$commentLength = strpos($string, '*/', $i);
+
+ // Comment end not exists, rest of string is inside comment
$commentLength = $commentLength !== false ? $commentLength - $i : strlen($string) - $i - 1;
if ($commentLength > 0) {
- $this->currentLine += substr_count($string, "\n", $i, $commentLength);
+ $this->currentLine += substr_count($string, "\n", $i, $commentLength); // Count new lines inside comment
$comment = substr($string, $i, $commentLength);
} else {
$comment = '';
}
- $i += $commentLength + 1; // */
+ $i += $commentLength + 1; // Continue outside of */
return $comment;
}
@@ -612,7 +618,7 @@ protected function parseComment($string, &$i)
*/
protected function processAtRule(array $subValues, array $stack)
{
- /** @var Parsed $parsed */
+ /** @var Root $parsed */
$parsed = $stack[0];
$rule = strtolower(array_shift($subValues));
View
2  lib/elements/Parsed.php → lib/elements/Root.php
@@ -35,7 +35,7 @@
require_once __DIR__ . '/Comment.php';
require_once __DIR__ . '/Property.php';
-class Parsed extends AtBlock
+class Root extends AtBlock
{
/** @var string */
public $charset = '';
Please sign in to comment.
Something went wrong with that request. Please try again.