class SassString in Sassy 7
Same name and namespace in other branches
- 7.3 phpsass/script/literals/SassString.php \SassString
SassString class. Provides operations and type testing for Sass strings. @package PHamlP @subpackage Sass.script.literals
Hierarchy
- class \SassLiteral
- class \SassString
Expanded class hierarchy of SassString
3 string references to 'SassString'
- SassScriptFunctions::get_var in phamlp/
sass/ script/ SassScriptFunctions.php - * Returns the variable whose name is the string. *
- SassScriptFunctions::quote in phamlp/
sass/ script/ SassScriptFunctions.php - * Add quotes to a string if the string isn't quoted, * or returns the same string if it is. *
- SassScriptFunctions::unquote in phamlp/
sass/ script/ SassScriptFunctions.php - * Removes quotes from a string if the string is quoted, or returns the same * string if it's not. *
File
- phamlp/
sass/ script/ literals/ SassString.php, line 20
View source
class SassString extends SassLiteral {
const MATCH = '/^(((["\'])(.*)(\\3))|(-[a-zA-Z][^\\s]*))/i';
const _MATCH = '/^(["\'])(.*?)(\\1)?$/';
// Used to match strings such as "Times New Roman",serif
const VALUE = 2;
const QUOTE = 3;
/**
* @var string string quote type; double or single quotes, or unquoted.
*/
private $quote;
/**
* class constructor
* @param string string
* @return SassString
*/
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;
}
}
/**
* String addition.
* Concatenates this and other.
* The resulting string will be quoted in the same way as this.
* @param sassString string to add to this
* @return sassString the string result
*/
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;
}
/**
* String multiplication.
* this is repeated other times
* @param sassNumber the number of times to repeat this
* @return sassString the string result
*/
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;
}
/**
* Returns the value of this string.
* @return string the string
*/
public function getValue() {
return $this->value;
}
/**
* Returns a string representation of the value.
* @return string string representation of the value.
*/
public function toString() {
return $this->quote . $this->value . $this->quote;
}
public function toVar() {
return SassScriptParser::$context
->getVariable($this->value);
}
/**
* Returns a value indicating if a token of this type can be matched at
* the start of the subject string.
* @param string the subject string
* @return mixed match at the start of the string or false if no match
*/
public static function isa($subject) {
return preg_match(self::MATCH, $subject, $matches) ? $matches[0] : false;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SassLiteral:: |
private static | property | * | |
SassLiteral:: |
protected | property | * | |
SassLiteral:: |
public | function | * Adds a child object to this. * | |
SassLiteral:: |
public static | function | * Asserts that the value of a literal is within the expected range * | |
SassLiteral:: |
public static | function | * Asserts that the literal is the expected type * | |
SassLiteral:: |
protected | function | * Returns the type of this * | 1 |
SassLiteral:: |
public | function | * The SassScript and operation. * | |
SassLiteral:: |
public | function | ||
SassLiteral:: |
public | function | * Bitwise AND the value of other and this value * | 1 |
SassLiteral:: |
public | function | * Bitwise NOT the value of other and the value of this * | |
SassLiteral:: |
public | function | * Bitwise OR the value of other and this value * | 1 |
SassLiteral:: |
public | function | * Bitwise XOR the value of other and the value of this * | 1 |
SassLiteral:: |
public | function | * SassScript ',' operation. * | |
SassLiteral:: |
public | function | * The SassScript default operation (e.g. $a $b, "foo" "bar"). * | |
SassLiteral:: |
public | function | * SassScript '/' operation. * | 2 |
SassLiteral:: |
public | function | * The SassScript == operation. * | 1 |
SassLiteral:: |
public | function | * The SassScript > operation. * | 1 |
SassLiteral:: |
public | function | * The SassScript >= operation. * | 1 |
SassLiteral:: |
public | function | * The SassScript < operation. * | 1 |
SassLiteral:: |
public | function | * The SassScript <= operation. * | 1 |
SassLiteral:: |
public | function | * SassScript '-' operation. * | 2 |
SassLiteral:: |
public | function | * SassScript '%' operation. * | 2 |
SassLiteral:: |
public | function | * The SassScript != operation. * | |
SassLiteral:: |
public | function | * The SassScript not operation. * | 1 |
SassLiteral:: |
public | function | * The SassScript or operation. * | |
SassLiteral:: |
public | function | * Shifts the value of this left by the number of bits given in value * | 1 |
SassLiteral:: |
public | function | * Shifts the value of this right by the number of bits given in value * | 1 |
SassLiteral:: |
public | function | * The SassScript xor operation. * | |
SassLiteral:: |
public | function | * Returns the boolean representation of the value of this * | |
SassLiteral:: |
public | function | * Getter. * | |
SassLiteral:: |
public | function | ||
SassString:: |
private | property | ||
SassString:: |
public | function |
* Returns the value of this string.
* Overrides SassLiteral:: |
|
SassString:: |
public static | function |
* Returns a value indicating if a token of this type can be matched at
* the start of the subject string.
* Overrides SassLiteral:: |
|
SassString:: |
constant | |||
SassString:: |
public | function |
* String addition.
* Concatenates this and other.
* The resulting string will be quoted in the same way as this.
* Overrides SassLiteral:: |
|
SassString:: |
public | function |
* String multiplication.
* this is repeated other times
* Overrides SassLiteral:: |
|
SassString:: |
constant | |||
SassString:: |
public | function |
* Returns a string representation of the value.
* Overrides SassLiteral:: |
|
SassString:: |
public | function | ||
SassString:: |
constant | |||
SassString:: |
constant | |||
SassString:: |
public | function |
* class constructor
* Overrides SassLiteral:: |