[Libreoffice-commits] core.git: unoxml/qa unoxml/source

Arkadiy Illarionov (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 25 19:43:25 UTC 2019


 unoxml/qa/unit/domtest.cxx              |    2 +-
 unoxml/source/dom/document.cxx          |   24 +++++++++---------------
 unoxml/source/dom/saxbuilder.cxx        |    9 ++++-----
 unoxml/source/rdf/librdf_repository.cxx |   10 ++++------
 4 files changed, 18 insertions(+), 27 deletions(-)

New commits:
commit 9a2fbfa3cc1da8bd9388d5b4c780e86f0dccc791
Author:     Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sun Jun 23 16:10:50 2019 +0300
Commit:     Arkadiy Illarionov <qarkai at gmail.com>
CommitDate: Tue Jun 25 21:42:40 2019 +0200

    Simplify Sequence iterations in unoxml
    
    Use range-based loops or replace with STL functions
    
    Change-Id: Ib1c49834a2c5c67a73ec05ba8f30c1d39a5c019c
    Reviewed-on: https://gerrit.libreoffice.org/74600
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
    Tested-by: Jenkins

diff --git a/unoxml/qa/unit/domtest.cxx b/unoxml/qa/unit/domtest.cxx
index 15e337772314..0a80d2a4cadc 100644
--- a/unoxml/qa/unit/domtest.cxx
+++ b/unoxml/qa/unit/domtest.cxx
@@ -181,7 +181,7 @@ struct TokenHandler
 {
     virtual ::sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence< ::sal_Int8 >& Identifier ) override
     {
-        return Identifier.getLength() ? Identifier[0] : 0;
+        return Identifier.hasElements() ? Identifier[0] : 0;
     }
 
     virtual uno::Sequence< ::sal_Int8 > SAL_CALL getUTF8Identifier( ::sal_Int32 ) override
diff --git a/unoxml/source/dom/document.cxx b/unoxml/source/dom/document.cxx
index 94dce24255ac..fc89b8aa4980 100644
--- a/unoxml/source/dom/document.cxx
+++ b/unoxml/source/dom/document.cxx
@@ -965,12 +965,10 @@ namespace DOM
         // add new namespaces to root node
         xmlNodePtr const pRoot = lcl_getDocumentRootPtr(m_aDocPtr);
         if (nullptr != pRoot) {
-            const beans::StringPair * pSeq = i_rNamespaces.getConstArray();
-            for (const beans::StringPair *pNsDef = pSeq;
-                 pNsDef < pSeq + i_rNamespaces.getLength(); ++pNsDef) {
-                OString prefix = OUStringToOString(pNsDef->First,
+            for (const beans::StringPair& rNsDef : i_rNamespaces) {
+                OString prefix = OUStringToOString(rNsDef.First,
                                     RTL_TEXTENCODING_UTF8);
-                OString href   = OUStringToOString(pNsDef->Second,
+                OString href   = OUStringToOString(rNsDef.Second,
                                     RTL_TEXTENCODING_UTF8);
                 // this will only add the ns if it does not exist already
                 xmlNewNs(pRoot, reinterpret_cast<const xmlChar*>(href.getStr()),
@@ -993,12 +991,10 @@ namespace DOM
         // add new namespaces to root node
         xmlNodePtr const pRoot = lcl_getDocumentRootPtr(m_aDocPtr);
         if (nullptr != pRoot) {
-            const beans::StringPair * pSeq = i_rNamespaces.getConstArray();
-            for (const beans::StringPair *pNsDef = pSeq;
-                 pNsDef < pSeq + i_rNamespaces.getLength(); ++pNsDef) {
-                OString prefix = OUStringToOString(pNsDef->First,
+            for (const beans::StringPair& rNsDef : i_rNamespaces) {
+                OString prefix = OUStringToOString(rNsDef.First,
                                     RTL_TEXTENCODING_UTF8);
-                OString href   = OUStringToOString(pNsDef->Second,
+                OString href   = OUStringToOString(rNsDef.Second,
                                     RTL_TEXTENCODING_UTF8);
                 // this will only add the ns if it does not exist already
                 xmlNewNs(pRoot, reinterpret_cast<const xmlChar*>(href.getStr()),
@@ -1012,13 +1008,11 @@ namespace DOM
                          i_xTokenHandler);
 
         // register namespace ids
-        const beans::Pair<OUString,sal_Int32>* pSeq = i_rRegisterNamespaces.getConstArray();
-        for (const beans::Pair<OUString,sal_Int32>* pNs = pSeq;
-             pNs < pSeq + i_rRegisterNamespaces.getLength(); ++pNs)
+        for (const beans::Pair<OUString,sal_Int32>& rNs : i_rRegisterNamespaces)
         {
-            OSL_ENSURE(pNs->Second >= FastToken::NAMESPACE,
+            OSL_ENSURE(rNs.Second >= FastToken::NAMESPACE,
                        "CDocument::fastSerialize(): invalid NS token id");
-            aContext.maNamespaceMap[ pNs->First ] = pNs->Second;
+            aContext.maNamespaceMap[ rNs.First ] = rNs.Second;
         }
 
         fastSaxify(aContext);
diff --git a/unoxml/source/dom/saxbuilder.cxx b/unoxml/source/dom/saxbuilder.cxx
index 994a6c0392f6..968971f29d2c 100644
--- a/unoxml/source/dom/saxbuilder.cxx
+++ b/unoxml/source/dom/saxbuilder.cxx
@@ -254,12 +254,11 @@ namespace DOM
         {
             setElementFastAttributes(aElement, xAttribs);
             Sequence< css::xml::Attribute > unknownAttribs = xAttribs->getUnknownAttributes();
-            sal_Int32 len = unknownAttribs.getLength();
-            for ( sal_Int32 i = 0; i < len; i++ )
+            for ( const auto& rUnknownAttrib : unknownAttribs )
             {
-                const OUString& rAttrValue = unknownAttribs[i].Value;
-                const OUString& rAttrName = unknownAttribs[i].Name;
-                const OUString& rAttrNamespace = unknownAttribs[i].NamespaceURL;
+                const OUString& rAttrValue = rUnknownAttrib.Value;
+                const OUString& rAttrName = rUnknownAttrib.Name;
+                const OUString& rAttrNamespace = rUnknownAttrib.NamespaceURL;
                 if ( !rAttrNamespace.isEmpty() )
                     aElement->setAttributeNS( rAttrNamespace, rAttrName, rAttrValue );
                 else
diff --git a/unoxml/source/rdf/librdf_repository.cxx b/unoxml/source/rdf/librdf_repository.cxx
index 22258ea6bec4..c04e4a0155ce 100644
--- a/unoxml/source/rdf/librdf_repository.cxx
+++ b/unoxml/source/rdf/librdf_repository.cxx
@@ -1407,12 +1407,10 @@ void SAL_CALL librdf_Repository::setStatementRDFa(
             "librdf_Repository::setStatementRDFa: no Predicates",
             *this, 1);
     }
-    for (sal_Int32 i = 0; i < i_rPredicates.getLength(); ++i) {
-        if (!i_rPredicates[i].is()) {
-            throw lang::IllegalArgumentException(
-                    "librdf_Repository::setStatementRDFa: Predicate is null",
-                *this, 1);
-        }
+    if (std::any_of(i_rPredicates.begin(), i_rPredicates.end(),
+            [](const uno::Reference< rdf::XURI >& rPredicate) { return !rPredicate.is(); })) {
+        throw lang::IllegalArgumentException(
+            "librdf_Repository::setStatementRDFa: Predicate is null", *this, 1);
     }
     if (!i_xObject.is()) {
         throw lang::IllegalArgumentException(


More information about the Libreoffice-commits mailing list