You are here

public static function SassScriptFunction::extractArgs in Sassy 7.3

Same name and namespace in other branches
  1. 7 phamlp/sass/script/SassScriptFunction.php \SassScriptFunction::extractArgs()
3 calls to SassScriptFunction::extractArgs()
SassMixinDefinitionNode::__construct in phpsass/tree/SassMixinDefinitionNode.php
SassMixinDefinitionNode constructor.
SassMixinNode::__construct in phpsass/tree/SassMixinNode.php
SassMixinDefinitionNode constructor.
SassScriptLexer::lex in phpsass/script/SassScriptLexer.php
Lex an expression into SassScript tokens.

File

phpsass/script/SassScriptFunction.php, line 168

Class

SassScriptFunction
SassScriptFunction class. Preforms a SassScript function. @package PHamlP @subpackage Sass.script

Code

public static function extractArgs($string) {
  $args = array();
  $arg = '';
  $paren = 0;
  $strpos = 0;
  $strlen = strlen($string);
  while ($strpos < $strlen) {
    $c = $string[$strpos++];
    switch ($c) {
      case '(':
        $paren += 1;
        $arg .= $c;
        break;
      case ')':
        $paren -= 1;
        $arg .= $c;
        break;
      case '"':
      case "'":
        $arg .= $c;
        do {
          $_c = $string[$strpos++];
          $arg .= $_c;
        } while ($_c !== $c);
        break;
      case ',':
        if ($paren) {
          $arg .= $c;
          break;
        }
        $args[] = trim($arg);
        $arg = '';
        break;
      default:
        $arg .= $c;
        break;
    }
  }
  if ($arg != '') {
    $args[] = trim($arg);
  }
  return $args;
}