tinyxml2 icon indicating copy to clipboard operation
tinyxml2 copied to clipboard

Getting last line number of a XMLNode

Open kcsaul opened this issue 5 years ago • 0 comments

Would it be possible to add a new method to XMLNode which returns the last line number? This would complement the existing GetLineNum method which returns the first line number.

I've a need to identify who's modified an element (or children of), querying version control to find out who last committed changes that affected the element line(s).

The last line number can almost be inferred based on the next sibling (using function below), however that doesn't always exist, nor can we always work it out using the next sibling of the parent. Ultimately, the function below fails in cases where none of the parents have another sibling element.

int GetLastLineNum(const tinyxml2::XMLNode* node) const
{
	if (auto next = node->NextSibling())
		return next->GetLineNum() - 1;

	if (auto parent = node->Parent())
		if (auto line = GetLastLineNum(parent))
			return line - 1;

	// Don't know
	return 0;
}

kcsaul avatar Feb 14 '20 10:02 kcsaul