src/parsers/RuleSet.php
public static function parseSelector($text){
		$text = preg_replace('/(\>|\+|~)\s+/is', '$1', $text);
		
		$selector	= null;
		
		foreach(preg_split('/\s+/', $text, -1, PREG_SPLIT_NO_EMPTY) as $part){
			if(!preg_match('/^([\>\+~]?)([^ >\+~]+)$/is', $part, $matches)) throw new \Exception("Invalid selector part '$part'");
			
			$selector = $selector ? $selector->add($matches[1] ? $matches[1] : false) : Selector::create();
			
			$offset = 0;
			
			$subtext = $matches[2];
			while($offset < strlen($subtext)){
				if(!preg_match('/^([\.:#]?)((:?[a-z0-9\-]|\*)+)/is', substr($subtext, $offset), $matches)) throw new \Exception("Invalid property at '".substr($text, $offset, 20)."'");
				
				switch($matches[1]){
					case '': $selector->setTagName($matches[2]); break;
					case '#': $selector->setIdentification($matches[2]); break;
					case '.': $selector->addClass($matches[2]); break;
					case ':': $selector->addPseudo($matches[2]); break;
					default: throw new \Exception("Knonwn type '".$matches[1]."'");
				}

				$offset+= strlen($matches[0]);
			}
		}

		return $selector->get();
	}
public static function parseSelector($text){
		$text = preg_replace('/(\>|\+|~)\s+/is', '$1', $text);
		
		$selector	= null;
		
		foreach(preg_split('/\s+/', $text, -1, PREG_SPLIT_NO_EMPTY) as $part){
			if(!preg_match('/^([\>\+~]?)([^ >\+~]+)$/is', $part, $matches)) throw new \Exception("Invalid selector part '$part'");
			
			$selector = $selector ? $selector->add($matches[1] ? $matches[1] : false) : Selector::create();
			
			$offset = 0;
			
			$subtext = $matches[2];
			while($offset < strlen($subtext)){
				if(!preg_match('/^([\.:#]?)((:?[a-z0-9\-]|\*)+)/is', substr($subtext, $offset), $matches)) throw new \Exception("Invalid property at '".substr($text, $offset, 20)."'");
				
				switch($matches[1]){
					case '': $selector->setTagName($matches[2]); break;
					case '#': $selector->setIdentification($matches[2]); break;
					case '.': $selector->addClass($matches[2]); break;
					case ':': $selector->addPseudo($matches[2]); break;
					default: throw new \Exception("Knonwn type '".$matches[1]."'");
				}

				$offset+= strlen($matches[0]);
			}
		}

		return $selector->get();
	}
public static function parseSelector ( $ text ) { $ text = preg_replace ( '/(\>|\+|~)\s+/is' , '$1' , $ text ) ; $ selector = null ; foreach ( preg_split ( '/\s+/' , $ text , - 1 , PREG_SPLIT_NO_EMPTY ) as $ part ) { if ( ! preg_match ( '/^([\>\+~]?)([^ >\+~]+)$/is' , $ part , $ matches ) ) throw new \ Exception ( "Invalid selector part '$part'" ) ; $ selector = $ selector ? $ selector -> add ( $ matches [ 1 ] ? $ matches [ 1 ] : false ) : Selector :: create ( ) ; $ offset = 0 ; $ subtext = $ matches [ 2 ] ; while ( $ offset < strlen ( $ subtext ) ) { if ( ! preg_match ( '/^([\.:#]?)((:?[a-z0-9\-]|\*)+)/is' , substr ( $ subtext , $ offset ) , $ matches ) ) throw new \ Exception ( "Invalid property at '" . substr ( $ text , $ offset , 20 ) . "'" ) ; switch ( $ matches [ 1 ] ) { case '' : $ selector -> setTagName ( $ matches [ 2 ] ) ; break ; case '#' : $ selector -> setIdentification ( $ matches [ 2 ] ) ; break ; case '.' : $ selector -> addClass ( $ matches [ 2 ] ) ; break ; case ':' : $ selector -> addPseudo ( $ matches [ 2 ] ) ; break ; default : throw new \ Exception ( "Knonwn type '" . $ matches [ 1 ] . "'" ) ; } $ offset += strlen ( $ matches [ 0 ] ) ; } } return $ selector -> get ( ) ; }
Parses a selector
@param string $text
@return \csslib\Selector
Parses a selector