Skip to content

Add DOMNode::compareDocumentPosition() - #12146

Merged
ndossche merged 2 commits into
php:masterfrom
ndossche:dom-compareDocumentPosition
Sep 8, 2023
Merged

ndossche merged 2 commits into
php:masterfrom
ndossche:dom-compareDocumentPosition

Conversation

@ndossche

@ndossche ndossche commented Sep 6, 2023

Copy link
Copy Markdown
Member

Comment thread UPGRADING
Comment on lines +34 to +39
. Added constant DOMNode::DOCUMENT_POSITION_DISCONNECTED.
. Added constant DOMNode::DOCUMENT_POSITION_PRECEDING.
. Added constant DOMNode::DOCUMENT_POSITION_FOLLOWING.
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINS.
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINED_BY.
. Added constant DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to make this an enum?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that too. The problem is that they're bitflags, so they might be OR'ed with eachother. That's something not supported with enums right now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum sets would be nice to have indeed :(

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just minor questions

Comment thread UPGRADING
Comment on lines +34 to +39
. Added constant DOMNode::DOCUMENT_POSITION_DISCONNECTED.
. Added constant DOMNode::DOCUMENT_POSITION_PRECEDING.
. Added constant DOMNode::DOCUMENT_POSITION_FOLLOWING.
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINS.
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINED_BY.
. Added constant DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum sets would be nice to have indeed :(

Comment thread ext/dom/node.c Outdated

/* Special case: comparing children and attributes.
* They belong to a different tree and are therefore hard to compare, but spec demands attributes to precede children
* according to the pre-order DFS numbering.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DFS?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depth-first search. I'll write it out in full.

Comment thread ext/dom/tests/compareDocumentPosition/attribute_child_order.phpt
Comment on lines +23 to +35
--EXPECT--
--- Compare 0 and 1 ---
int(36)
--- Compare 0 and 2 ---
int(36)
--- Compare 1 and 2 ---
int(36)
--- Compare 1 and 0 ---
int(34)
--- Compare 2 and 0 ---
int(34)
--- Compare 2 and 1 ---
int(34)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the values meaningful?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll clean it up so it's easier to understand.

Comment on lines +36 to +38
echo "--- strong & bar ---\n";
var_dump($bar->nextElementSibling->compareDocumentPosition($bar) === DOMNode::DOCUMENT_POSITION_PRECEDING);
var_dump($bar->compareDocumentPosition($bar->nextElementSibling) === DOMNode::DOCUMENT_POSITION_FOLLOWING);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would the two strong tags compare?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a test for this.

@ndossche
ndossche merged commit 880faa3 into php:master Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants