Skip to content

Commit

Permalink
minor code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dryabov committed Apr 20, 2015
1 parent 62adda4 commit 52068aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pharse.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ static public function dom_format($root, $options = array())
$formatter = new HTML_Formatter($options);
return $formatter->format($root);
}
}
}
19 changes: 10 additions & 9 deletions pharse_node_html.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
class HTML_Node
{

/**
* Element Node, used for regular elements
*/
Expand Down Expand Up @@ -1946,16 +1945,18 @@ public function select($query = '*', $index = false, $recursive = true, $check_s
$s = new $this->selectClass($this, $query, $check_self, $recursive);
$res = $s->result;
unset($s);
if (is_array($res) && ($index === true) && (count($res) === 1)) {
return $res[0];
} elseif (is_int($index) && is_array($res)) {
if ($index < 0) {
$index += count($res);
if (is_array($res)) {
if (($index === true) && (count($res) === 1)) {
return $res[0];
}
if (is_int($index)) {
if ($index < 0) {
$index += count($res);
}
return ($index < count($res)) ? $res[$index] : null;
}
return ($index < count($res)) ? $res[$index] : null;
} else {
return $res;
}
return $res;
}

/**
Expand Down
22 changes: 12 additions & 10 deletions pharse_parser_html.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ protected function parse_doctype()
{
$start = $this->pos;
if ($this->next_search('[>', false) === self::TOK_UNKNOWN) {
if ($this->doc[$this->pos] === '[') {
if (($this->next_pos(']', false) !== self::TOK_UNKNOWN) || ($this->next_pos('>', false) !== self::TOK_UNKNOWN)) {
$this->addError('Invalid doctype');
return false;
}
if ($this->doc[$this->pos] === '['
&& (($this->next_pos(']', false) !== self::TOK_UNKNOWN) || ($this->next_pos('>', false) !== self::TOK_UNKNOWN))
) {
$this->addError('Invalid doctype');
return false;
}

$this->token_start = $start;
Expand Down Expand Up @@ -376,7 +376,9 @@ protected function parse_tag_default()
if ($this->token === self::TOK_SLASH_FORWARD) {
$this->status['self_close'] = true;
$this->next();
} elseif ((($this->status['tag_name'][0] === '?') && ($this->doc[$this->pos] === '?')) || (($this->status['tag_name'][0] === '%') && ($this->doc[$this->pos] === '%'))) {
} elseif ((($this->status['tag_name'][0] === '?') && ($this->doc[$this->pos] === '?'))
|| (($this->status['tag_name'][0] === '%') && ($this->doc[$this->pos] === '%'))
) {
$this->status['self_close'] = true;
$this->pos++;

Expand All @@ -386,8 +388,8 @@ protected function parse_tag_default()
$this->token = self::TOK_UNKNOWN;
}
}/* else {
$this->status['self_close'] = false;
}*/
$this->status['self_close'] = false;
}*/
}

if ($this->token !== self::TOK_TAG_CLOSE) {
Expand Down Expand Up @@ -452,7 +454,7 @@ protected function parse_tag()
$this->status['last_pos'] = $start - 1;
return true;
//} else {
// return false;
// return false;
//}
}

Expand Down Expand Up @@ -822,7 +824,7 @@ class HTML_Parser_HTML5 extends HTML_Parser
* @access private
*/
public $tags_optional_close = array(
//Current tag => Previous tag
//Current tag => Previous tag
'li' => array('li' => true),
'dt' => array('dt' => true, 'dd' => true),
'dd' => array('dt' => true, 'dd' => true),
Expand Down
7 changes: 3 additions & 4 deletions pharse_selector_html.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,10 +853,9 @@ protected function parse_adjacent()
}

foreach ($tmp as $t) {
if (($sibling = $t->getNextSibling()) !== false) {
if ($sibling->match($c, true, $this->custom_filter_map)) {
$this->result[] = $sibling;
}
$sibling = $t->getNextSibling();
if ($sibling !== false && $sibling->match($c, true, $this->custom_filter_map)) {
$this->result[] = $sibling;
}
}

Expand Down

0 comments on commit 52068aa

Please sign in to comment.