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 <vmiklos@collabora.com>
This commit is contained in:
Miklos Vajna
2023-11-16 08:31:08 +01:00
parent c0fffdc36d
commit 06e3877dc2
2 changed files with 9 additions and 4 deletions
+5
View File
@@ -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);
+4 -4
View File
@@ -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>());
}