include/comphelper/sequenceashashmap.hxx | 5 +++++ xmloff/qa/unit/text.cxx | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-)
New commits: commit 06e3877dc2cf22e00d04b48453e9ab0b948c3ca2 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Nov 15 20:08:48 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Nov 16 08:31:08 2023 +0100 comphelper: use c++20 contains() instead of find() and end() Whether an element is contained inside a container is better to be checked with contains() instead of find() because contains() conveys the intent more clearly. Change-Id: I267d915c95fcf9c98b2e11daa89c8fe801e59a75 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159484 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/comphelper/sequenceashashmap.hxx b/include/comphelper/sequenceashashmap.hxx index 59ab4c298d76..f5af2e28de50 100644 --- a/include/comphelper/sequenceashashmap.hxx +++ b/include/comphelper/sequenceashashmap.hxx @@ -405,6 +405,11 @@ class SAL_WARN_UNUSED COMPHELPER_DLLPUBLIC SequenceAsHashMap return m_aMap.find(rKey); } + bool contains(const OUString& rKey) + { + return m_aMap.contains(rKey); + } + iterator erase(iterator it) { return m_aMap.erase(it); diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index 5188770a32ba..2a5350423c0d 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -126,7 +126,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testBibliographyLocalUrl) uno::Reference<beans::XPropertySet> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); xField.set(xPortion->getPropertyValue("TextField"), uno::UNO_QUERY); comphelper::SequenceAsHashMap aMap(xField->getPropertyValue("Fields")); - CPPUNIT_ASSERT(aMap.find("LocalURL") != aMap.end()); + CPPUNIT_ASSERT(aMap.contains("LocalURL")); auto aActual = aMap["LocalURL"].get<OUString>(); CPPUNIT_ASSERT_EQUAL(OUString("file:///home/me/test.pdf"), aActual); } @@ -165,15 +165,15 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testBibliographyTargetURL1) xField.set(xPortion->getPropertyValue("TextField"), uno::UNO_QUERY); comphelper::SequenceAsHashMap aMap(xField->getPropertyValue("Fields")); - CPPUNIT_ASSERT(aMap.find("URL") != aMap.end()); + CPPUNIT_ASSERT(aMap.contains("URL")); CPPUNIT_ASSERT_EQUAL(OUString("https://display.url/test1.pdf#page=1"), aMap["URL"].get<OUString>()); - CPPUNIT_ASSERT(aMap.find("TargetURL") != aMap.end()); + CPPUNIT_ASSERT(aMap.contains("TargetURL")); CPPUNIT_ASSERT_EQUAL(OUString("https://target.url/test2.pdf#page=2"), aMap["TargetURL"].get<OUString>()); - CPPUNIT_ASSERT(aMap.find("TargetType") != aMap.end()); + CPPUNIT_ASSERT(aMap.contains("TargetType")); CPPUNIT_ASSERT_EQUAL(OUString("1"), aMap["TargetType"].get<OUString>()); }