[Libreoffice-commits] libmspub.git: src/lib

Miklos Vajna vmiklos at collabora.co.uk
Thu Sep 7 07:32:38 UTC 2017


 src/lib/Fill.cpp              |    8 ++++----
 src/lib/MSPUBCollector.cpp    |   36 ++++++++++++++++++------------------
 src/lib/MSPUBMetaData.cpp     |    4 ++--
 src/lib/MSPUBParser.cpp       |   30 +++++++++++++-----------------
 src/lib/MSPUBParser2k.cpp     |   19 +++++++++----------
 src/lib/PolygonUtils.cpp      |    4 ++--
 src/lib/ShapeGroupElement.cpp |    8 ++++----
 7 files changed, 52 insertions(+), 57 deletions(-)

New commits:
commit 3ac90c42f722af561596201753f8907ce3856775
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Sep 7 09:32:18 2017 +0200

    Convert explicit for loops to range-based ones where possible
    
    This is most useful in libmspub::MSPUBMetaData::readPropertySetStream()
    to avoid repeating ourselves.
    
    Change-Id: Iff23ff28b8f0959a8b552d17d6c9a6912221d4bf

diff --git a/src/lib/Fill.cpp b/src/lib/Fill.cpp
index bb0a1ca..9cf379f 100644
--- a/src/lib/Fill.cpp
+++ b/src/lib/Fill.cpp
@@ -156,15 +156,15 @@ void GradientFill::getProperties(librevenge::RVNGPropertyList *out) const
     out->insert("libmspub:shade", "normal");
     break;
   }
-  for (unsigned i = 0; i < m_stops.size(); ++i)
+  for (const auto &stop : m_stops)
   {
-    Color c = m_stops[i].m_colorReference.getFinalColor(m_owner->m_paletteColors);
+    Color c = stop.m_colorReference.getFinalColor(m_owner->m_paletteColors);
     librevenge::RVNGPropertyList stopProps;
     librevenge::RVNGString sValue;
-    sValue.sprintf("%d%%", m_stops[i].m_offsetPercent);
+    sValue.sprintf("%d%%", stop.m_offsetPercent);
     stopProps.insert("svg:offset", sValue);
     stopProps.insert("svg:stop-color", MSPUBCollector::getColorString(c));
-    sValue.sprintf("%d%%", (int)(m_stops[i].m_opacity * 100));
+    sValue.sprintf("%d%%", (int)(stop.m_opacity * 100));
     stopProps.insert("svg:stop-opacity", sValue);
     ret.append(stopProps);
   }
diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index 387db1c..af0e25f 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -608,9 +608,9 @@ std::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, cons
   }
   else
   {
-    for (unsigned i = 0; i < info.m_lines.size(); ++i)
+    for (const auto &line : info.m_lines)
     {
-      hasStroke = hasStroke || info.m_lines[i].m_lineExists;
+      hasStroke = hasStroke || line.m_lineExists;
       if (hasStroke)
       {
         break;
@@ -1007,10 +1007,10 @@ std::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, cons
     if (isTable)
     {
       librevenge::RVNGPropertyListVector columnWidths;
-      for (unsigned col = 0; col < (get(info.m_tableInfo).m_columnWidthsInEmu.size()); ++col)
+      for (unsigned int col : get(info.m_tableInfo).m_columnWidthsInEmu)
       {
         librevenge::RVNGPropertyList columnWidth;
-        columnWidth.insert("style:column-width", double(get(info.m_tableInfo).m_columnWidthsInEmu[col]) / EMUS_IN_INCH);
+        columnWidth.insert("style:column-width", double(col) / EMUS_IN_INCH);
         columnWidths.append(columnWidth);
       }
       props.insert("librevenge:table-columns", columnWidths);
@@ -1118,16 +1118,16 @@ std::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, cons
           props.insert("fo:column-gap", (double)ngap / EMUS_IN_INCH);
       }
       m_painter->startTextObject(props);
-      for (unsigned i_lines = 0; i_lines < text.size(); ++i_lines)
+      for (const auto &line : text)
       {
-        librevenge::RVNGPropertyList paraProps = getParaStyleProps(text[i_lines].style, text[i_lines].style.m_defaultCharStyleIndex);
+        librevenge::RVNGPropertyList paraProps = getParaStyleProps(line.style, line.style.m_defaultCharStyleIndex);
         m_painter->openParagraph(paraProps);
-        for (unsigned i_spans = 0; i_spans < text[i_lines].spans.size(); ++i_spans)
+        for (unsigned i_spans = 0; i_spans < line.spans.size(); ++i_spans)
         {
           librevenge::RVNGString textString;
-          appendCharacters(textString, text[i_lines].spans[i_spans].chars,
+          appendCharacters(textString, line.spans[i_spans].chars,
                            getCalculatedEncoding());
-          librevenge::RVNGPropertyList charProps = getCharStyleProps(text[i_lines].spans[i_spans].style, text[i_lines].style.m_defaultCharStyleIndex);
+          librevenge::RVNGPropertyList charProps = getCharStyleProps(line.spans[i_spans].style, line.style.m_defaultCharStyleIndex);
           m_painter->openSpan(charProps);
           separateSpacesAndInsertText(m_painter, textString);
           m_painter->closeSpan();
@@ -1615,16 +1615,16 @@ void MSPUBCollector::addBlackToPaletteIfNecessary()
 
 void MSPUBCollector::assignShapesToPages()
 {
-  for (unsigned i = 0; i < m_topLevelShapes.size(); ++i)
+  for (auto &topLevelShape : m_topLevelShapes)
   {
-    unsigned *ptr_pageSeqNum = getIfExists(m_pageSeqNumsByShapeSeqNum, m_topLevelShapes[i]->getSeqNum());
-    m_topLevelShapes[i]->setup(std::bind(&MSPUBCollector::setupShapeStructures, this, _1));
+    unsigned *ptr_pageSeqNum = getIfExists(m_pageSeqNumsByShapeSeqNum, topLevelShape->getSeqNum());
+    topLevelShape->setup(std::bind(&MSPUBCollector::setupShapeStructures, this, _1));
     if (ptr_pageSeqNum)
     {
       PageInfo *ptr_page = getIfExists(m_pagesBySeqNum, *ptr_pageSeqNum);
       if (ptr_page)
       {
-        ptr_page->m_shapeGroupsOrdered.push_back(m_topLevelShapes[i]);
+        ptr_page->m_shapeGroupsOrdered.push_back(topLevelShape);
       }
     }
   }
@@ -1738,10 +1738,10 @@ bool MSPUBCollector::go()
   }
   else
   {
-    for (unsigned i = 0; i < m_pageSeqNumsOrdered.size(); ++i)
+    for (unsigned int i : m_pageSeqNumsOrdered)
     {
       std::map<unsigned, PageInfo>::const_iterator iter =
-        m_pagesBySeqNum.find(m_pageSeqNumsOrdered[i]);
+        m_pagesBySeqNum.find(i);
       if (iter != m_pagesBySeqNum.end() && !pageIsMaster(iter->first))
       {
         writePage(iter->first);
@@ -1767,11 +1767,11 @@ bool MSPUBCollector::addTextString(const std::vector<TextParagraph> &str, unsign
 void MSPUBCollector::ponderStringEncoding(
   const std::vector<TextParagraph> &str)
 {
-  for (unsigned i = 0; i < str.size(); ++i)
+  for (const auto &i : str)
   {
-    for (unsigned j = 0; j < str[i].spans.size(); ++j)
+    for (unsigned j = 0; j < i.spans.size(); ++j)
     {
-      const std::vector<unsigned char> &chars = str[i].spans[j].chars;
+      const std::vector<unsigned char> &chars = i.spans[j].chars;
       m_allText.insert(m_allText.end(), chars.begin(), chars.end());
     }
   }
diff --git a/src/lib/MSPUBMetaData.cpp b/src/lib/MSPUBMetaData.cpp
index f9ffb8f..779233a 100644
--- a/src/lib/MSPUBMetaData.cpp
+++ b/src/lib/MSPUBMetaData.cpp
@@ -106,9 +106,9 @@ void libmspub::MSPUBMetaData::readPropertySetStream(librevenge::RVNGInputStream
   uint16_t data2 = readU16(input);
   uint16_t data3 = readU16(input);
   uint8_t data4[8];
-  for (int i = 0; i < 8; i++)
+  for (unsigned char &i : data4)
   {
-    data4[i] = readU8(input);
+    i = readU8(input);
   }
   // Pretty-printed GUID is 36 bytes + the terminating null-character.
   char FMTID0[37];
diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index bfa7450..0cb0e28 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -354,42 +354,39 @@ bool MSPUBParser::parseContents(librevenge::RVNGInputStream *input)
         return false;
       }
       const ContentChunkReference &documentChunk = m_contentChunks.at(m_documentChunkIndex.get());
-      for (unsigned i_pal = 0; i_pal < m_paletteChunkIndices.size(); ++i_pal)
+      for (unsigned int paletteChunkIndex : m_paletteChunkIndices)
       {
-        const ContentChunkReference &paletteChunk = m_contentChunks.at(m_paletteChunkIndices[i_pal]);
+        const ContentChunkReference &paletteChunk = m_contentChunks.at(paletteChunkIndex);
         input->seek(paletteChunk.offset, librevenge::RVNG_SEEK_SET);
         if (! parsePaletteChunk(input, paletteChunk))
         {
           return false;
         }
       }
-      for (unsigned i_ba = 0; i_ba < m_borderArtChunkIndices.size();
-           ++i_ba)
+      for (unsigned int borderArtChunkIndex : m_borderArtChunkIndices)
       {
         const ContentChunkReference &baChunk =
-          m_contentChunks.at(m_borderArtChunkIndices[i_ba]);
+          m_contentChunks.at(borderArtChunkIndex);
         input->seek(baChunk.offset, librevenge::RVNG_SEEK_SET);
         if (!parseBorderArtChunk(input, baChunk))
         {
           return false;
         }
       }
-      for (unsigned i_shape = 0; i_shape < m_shapeChunkIndices.size();
-           ++i_shape)
+      for (unsigned int shapeChunkIndex : m_shapeChunkIndices)
       {
         const ContentChunkReference &shapeChunk =
-          m_contentChunks.at(m_shapeChunkIndices[i_shape]);
+          m_contentChunks.at(shapeChunkIndex);
         input->seek(shapeChunk.offset, librevenge::RVNG_SEEK_SET);
         if (!parseShape(input, shapeChunk))
         {
           return false;
         }
       }
-      for (unsigned i_font = 0; i_font < m_fontChunkIndices.size();
-           ++i_font)
+      for (unsigned int fontChunkIndex : m_fontChunkIndices)
       {
         const ContentChunkReference &fontChunk =
-          m_contentChunks.at(m_fontChunkIndices[i_font]);
+          m_contentChunks.at(fontChunkIndex);
         input->seek(fontChunk.offset, librevenge::RVNG_SEEK_SET);
         if (!parseFontChunk(input, fontChunk))
         {
@@ -401,9 +398,9 @@ bool MSPUBParser::parseContents(librevenge::RVNGInputStream *input)
       {
         return false;
       }
-      for (unsigned i_page = 0; i_page < m_pageChunkIndices.size(); ++i_page)
+      for (unsigned int pageChunkIndex : m_pageChunkIndices)
       {
-        const ContentChunkReference &pageChunk = m_contentChunks.at(m_pageChunkIndices[i_page]);
+        const ContentChunkReference &pageChunk = m_contentChunks.at(pageChunkIndex);
         input->seek(pageChunk.offset, librevenge::RVNG_SEEK_SET);
         if (!parsePageChunk(input, pageChunk))
         {
@@ -615,9 +612,9 @@ bool MSPUBParser::parsePageChunk(librevenge::RVNGInputStream *input, const Conte
     }
     else if (info.id == THIS_MASTER_NAME)
     {
-      for (unsigned i = 0; i < info.stringData.size(); ++i)
+      for (unsigned char i : info.stringData)
       {
-        if (info.stringData[i] != 0)
+        if (i != 0)
         {
           m_collector->designateMasterPage(chunk.seqNum);
         }
@@ -2262,13 +2259,12 @@ FOPTValues MSPUBParser::extractFOPTValues(librevenge::RVNGInputStream *input, co
       complexIds.push_back(id);
     }
   }
-  for (unsigned i = 0; i < complexIds.size(); ++i)
+  for (unsigned short id : complexIds)
   {
     if (!stillReading(input, record.contentsOffset + record.contentsLength))
     {
       break;
     }
-    unsigned short id = complexIds[i];
     unsigned length = ret.m_scalarValues[id];
     if (!length)
     {
diff --git a/src/lib/MSPUBParser2k.cpp b/src/lib/MSPUBParser2k.cpp
index 62342c4..95f8c8b 100644
--- a/src/lib/MSPUBParser2k.cpp
+++ b/src/lib/MSPUBParser2k.cpp
@@ -431,9 +431,9 @@ bool MSPUBParser2k::parseContents(librevenge::RVNGInputStream *input)
   }
 
 
-  for (unsigned i = 0; i < m_paletteChunkIndices.size(); ++i)
+  for (unsigned int paletteChunkIndex : m_paletteChunkIndices)
   {
-    const ContentChunkReference &chunk = m_contentChunks.at(m_paletteChunkIndices[i]);
+    const ContentChunkReference &chunk = m_contentChunks.at(paletteChunkIndex);
     input->seek(chunk.offset, librevenge::RVNG_SEEK_SET);
     input->seek(0xA0, librevenge::RVNG_SEEK_CUR);
     for (unsigned j = 0; j < 8; ++j)
@@ -444,9 +444,9 @@ bool MSPUBParser2k::parseContents(librevenge::RVNGInputStream *input)
     }
   }
 
-  for (unsigned i = 0; i < m_imageDataChunkIndices.size(); ++i)
+  for (unsigned int imageDataChunkIndex : m_imageDataChunkIndices)
   {
-    const ContentChunkReference &chunk = m_contentChunks.at(m_imageDataChunkIndices[i]);
+    const ContentChunkReference &chunk = m_contentChunks.at(imageDataChunkIndex);
     input->seek(chunk.offset + 4, librevenge::RVNG_SEEK_SET);
     unsigned toRead = readU32(input);
     librevenge::RVNGBinaryData img;
@@ -460,9 +460,9 @@ bool MSPUBParser2k::parseContents(librevenge::RVNGInputStream *input)
     m_collector->addImage(++m_lastAddedImage, WMF, img);
   }
 
-  for (unsigned i = 0; i < m_shapeChunkIndices.size(); ++i)
+  for (unsigned int shapeChunkIndex : m_shapeChunkIndices)
   {
-    parse2kShapeChunk(m_contentChunks.at(m_shapeChunkIndices[i]), input);
+    parse2kShapeChunk(m_contentChunks.at(shapeChunkIndex), input);
   }
 
   return true;
@@ -515,9 +515,8 @@ bool MSPUBParser2k::parse2kShapeChunk(const ContentChunkReference &chunk, librev
   {
     // ignore non top level shapes
     int i_page = -1;
-    for (unsigned j = 0; j < m_pageChunkIndices.size(); ++j)
+    for (unsigned int pageIndex : m_pageChunkIndices)
     {
-      unsigned pageIndex = m_pageChunkIndices[j];
       if (m_contentChunks.at(pageIndex).seqNum == chunk.parentSeqNum)
       {
         i_page = pageIndex;
@@ -598,9 +597,9 @@ bool MSPUBParser2k::parseGroup(librevenge::RVNGInputStream *input, unsigned seqN
   if (it != m_chunkChildIndicesById.end())
   {
     const std::vector<unsigned> &chunkChildIndices = it->second;
-    for (unsigned i = 0; i < chunkChildIndices.size(); ++i)
+    for (unsigned int chunkChildIndex : chunkChildIndices)
     {
-      const ContentChunkReference &childChunk = m_contentChunks.at(chunkChildIndices[i]);
+      const ContentChunkReference &childChunk = m_contentChunks.at(chunkChildIndex);
       if (childChunk.type == SHAPE || childChunk.type == GROUP)
       {
         retVal = retVal && parse2kShapeChunk(childChunk, input, page, false);
diff --git a/src/lib/PolygonUtils.cpp b/src/lib/PolygonUtils.cpp
index ef55521..7c0ff80 100644
--- a/src/lib/PolygonUtils.cpp
+++ b/src/lib/PolygonUtils.cpp
@@ -5828,9 +5828,9 @@ void drawEmulatedLine(std::shared_ptr<const CustomShape> shape, ShapeType shapeT
   }
   else
   {
-    for (unsigned i = 0; i < lineInfos.size(); ++i)
+    for (auto &lineInfo : lineInfos)
     {
-      lineInfos[i].output(painter, graphicsProps);
+      lineInfo.output(painter, graphicsProps);
     }
   }
 }
diff --git a/src/lib/ShapeGroupElement.cpp b/src/lib/ShapeGroupElement.cpp
index f94ce8e..c61d412 100644
--- a/src/lib/ShapeGroupElement.cpp
+++ b/src/lib/ShapeGroupElement.cpp
@@ -45,9 +45,9 @@ void ShapeGroupElement::setTransform(const VectorTransformation2D &transform)
 void ShapeGroupElement::setup(std::function<void(ShapeGroupElement &self)> visitor)
 {
   visitor(*this);
-  for (unsigned i = 0; i < m_children.size(); ++i)
+  for (auto &i : m_children)
   {
-    m_children[i]->setup(visitor);
+    i->setup(visitor);
   }
 }
 
@@ -67,9 +67,9 @@ void ShapeGroupElement::visit(std::function<
   VectorTransformation2D foldedTransform = VectorTransformation2D::fromTranslate(-offsetX, -offsetY)
                                            * parentFoldedTransform * VectorTransformation2D::fromTranslate(offsetX, offsetY) * m_transform;
   std::function<void(void)> afterOp = visitor(info, relativeTo, foldedTransform, isGroup(), m_transform);
-  for (unsigned i = 0; i < m_children.size(); ++i)
+  for (const auto &i : m_children)
   {
-    m_children[i]->visit(visitor, coord, foldedTransform);
+    i->visit(visitor, coord, foldedTransform);
   }
   afterOp();
 }


More information about the Libreoffice-commits mailing list