From 5ebe81f068dba0c141ebe92f64731d0c95179dae Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 25 Mar 2024 16:28:39 +0900 Subject: editeng: make it ContentNode::FindFeature clearer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia3498df3cb11b06ac71e3c75839cc98cc0f3d88c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165337 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- editeng/source/editeng/ContentNode.cxx | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/editeng/source/editeng/ContentNode.cxx b/editeng/source/editeng/ContentNode.cxx index a02a3fde0d39..08bf250b6c86 100644 --- a/editeng/source/editeng/ContentNode.cxx +++ b/editeng/source/editeng/ContentNode.cxx @@ -947,16 +947,20 @@ EditCharAttrib* CharAttribList::FindEmptyAttrib( sal_uInt16 nWhich, sal_Int32 nP return nullptr; } -namespace { +namespace +{ class FindByStartPos { sal_Int32 mnPos; public: - explicit FindByStartPos(sal_Int32 nPos) : mnPos(nPos) {} - bool operator() (const std::unique_ptr& r) const + explicit FindByStartPos(sal_Int32 nPos) + : mnPos(nPos) + {} + + bool operator() (std::unique_ptr const& pCharAttrib) const { - return r->GetStart() >= mnPos; + return pCharAttrib->GetStart() >= mnPos; } }; @@ -965,16 +969,28 @@ public: const EditCharAttrib* CharAttribList::FindFeature( sal_Int32 nPos ) const { // First, find the first attribute that starts at or after specified position. - AttribsType::const_iterator it = + AttribsType::const_iterator iterator = std::find_if(maAttribs.begin(), maAttribs.end(), FindByStartPos(nPos)); - if (it == maAttribs.end()) + if (iterator == maAttribs.end()) + { // All attributes are before the specified position. return nullptr; + } // And find the first attribute with feature. - it = std::find_if(it, maAttribs.end(), [](const std::unique_ptr& aAttrib) { return aAttrib->IsFeature(); } ); - return it == maAttribs.end() ? nullptr : it->get(); + iterator = std::find_if(iterator, maAttribs.end(), [](const std::unique_ptr& aAttrib) { + return aAttrib->IsFeature(); + }); + + if (iterator == maAttribs.end()) + { + // Couldn't find the feature + return nullptr; + } + + // Found + return iterator->get(); } void CharAttribList::DeleteEmptyAttribs() -- cgit