SassString.php in Sassy 7
File
phamlp/sass/script/literals/SassString.php
View source
<?php
require_once 'SassLiteral.php';
class SassString extends SassLiteral {
const MATCH = '/^(((["\'])(.*)(\\3))|(-[a-zA-Z][^\\s]*))/i';
const _MATCH = '/^(["\'])(.*?)(\\1)?$/';
const VALUE = 2;
const QUOTE = 3;
private $quote;
public function __construct($value) {
preg_match(self::_MATCH, $value, $matches);
if (isset($matches[self::QUOTE])) {
$this->quote = $matches[self::QUOTE];
$this->value = $matches[self::VALUE];
}
else {
$this->quote = '';
$this->value = $value;
}
}
public function op_plus($other) {
if (!$other instanceof SassString) {
throw new SassStringException('{what} must be a {type}', array(
'{what}' => Phamlp::t('sass', 'Value'),
'{type}' => Phamlp::t('sass', 'string'),
), SassScriptParser::$context->node);
}
$this->value .= $other->value;
return $this;
}
public function op_times($other) {
if (!$other instanceof SassNumber || !$other
->isUnitless()) {
throw new SassStringException('{what} must be a {type}', array(
'{what}' => Phamlp::t('sass', 'Value'),
'{type}' => Phamlp::t('sass', 'unitless number'),
), SassScriptParser::$context->node);
}
$this->value = str_repeat($this->value, $other->value);
return $this;
}
public function getValue() {
return $this->value;
}
public function toString() {
return $this->quote . $this->value . $this->quote;
}
public function toVar() {
return SassScriptParser::$context
->getVariable($this->value);
}
public static function isa($subject) {
return preg_match(self::MATCH, $subject, $matches) ? $matches[0] : false;
}
}
Classes
Name |
Description |
SassString |
SassString class.
Provides operations and type testing for Sass strings.
@package PHamlP
@subpackage Sass.script.literals |