summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-03-25 16:28:39 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-04-04 04:06:40 +0200
commit5ebe81f068dba0c141ebe92f64731d0c95179dae (patch)
treeca9979680db1a33601ef2944c2daccb73478ab95
parent7f4d31f2d6f37d280ae3e65c86077a7423dff0cc (diff)
editeng: make it ContentNode::FindFeature clearer
Change-Id: Ia3498df3cb11b06ac71e3c75839cc98cc0f3d88c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165337 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--editeng/source/editeng/ContentNode.cxx32
1 files 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<EditCharAttrib>& r) const
+ explicit FindByStartPos(sal_Int32 nPos)
+ : mnPos(nPos)
+ {}
+
+ bool operator() (std::unique_ptr<EditCharAttrib> 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<EditCharAttrib>& aAttrib) { return aAttrib->IsFeature(); } );
- return it == maAttribs.end() ? nullptr : it->get();
+ iterator = std::find_if(iterator, maAttribs.end(), [](const std::unique_ptr<EditCharAttrib>& aAttrib) {
+ return aAttrib->IsFeature();
+ });
+
+ if (iterator == maAttribs.end())
+ {
+ // Couldn't find the feature
+ return nullptr;
+ }
+
+ // Found
+ return iterator->get();
}
void CharAttribList::DeleteEmptyAttribs()