Skip to content

Commit

Permalink
Update nokogiri.php
Browse files Browse the repository at this point in the history
  • Loading branch information
olamedia committed Feb 14, 2012
1 parent 894928d commit 073113b
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions nokogiri.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class nokogiri implements IteratorAggregate{
const
regexp =
"/(?P<tag>[a-z0-9]+)?(\[(?P<attr>\S+)=(?P<value>\S+)\])?(#(?P<id>\S+))?(\.(?P<class>[^\s:>#\.]+))?(:(?P<pseudo>(first|last|nth)-child(\([^\)]+)\))))?\s*(?P<rel>>)?/isS"
"/(?P<tag>[a-z0-9]+)?(\[(?P<attr>\S+)=(?P<value>[^\]]+)\])?(#(?P<id>[^\s:>#\.]+))?(\.(?P<class>[^\s:>#\.]+))?(:(?P<pseudo>(first|last|nth)-child)(\((?P<expr>[^\)]+)\)))?\s*(?P<rel>>)?/isS"
;
protected $_source = '';
/**
Expand Down Expand Up @@ -101,10 +101,7 @@ protected function getXpath(){
}
public function getXpathSubquery($expression, $rel = false){
$query = '';
if (preg_match($this->getRegexp(), $expression, $subs)){
$tag = isset($subs['tag']) && !empty($subs['tag'])?$subs['tag']:'*';
$query = ($rel?'/':'//').$tag;
//var_dump($subs);
if (preg_match(self::regexp, $expression, $subs)){
$brackets = array();
if (isset($subs['id']) && '' !== $subs['id']){
$brackets[] = "@id='".$subs['id']."'";
Expand Down Expand Up @@ -138,13 +135,12 @@ public function getXpathSubquery($expression, $rel = false){
}
}
}
if ($c = count($brackets)){
if ($c > 1){
$query .= '[('.implode(') and (', $brackets).')]';
}else{
$query .= '['.implode(' and ', $brackets).']';
}
}
$query = ($rel?'/':'//').
((isset($subs['tag']) && '' !== $subs['tag'])?$subs['tag']:'*').
(($c = count($brackets))?
($c>1?'[('.implode(') and (', $brackets).')]':'['.implode(' and ', $brackets).']')
:'')
;
$left = trim(substr($expression, strlen($subs[0])));
if ('' !== $left){
$query .= $this->getXpathSubquery($left, '>'===$subs['rel']);
Expand Down

0 comments on commit 073113b

Please sign in to comment.