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

Miklos Vajna vmiklos at collabora.co.uk
Tue Nov 7 08:50:51 UTC 2017


 src/lib/MSPUBCollector.cpp |   25 +++++++++++--------------
 src/lib/MSPUBParser.cpp    |   10 +++++-----
 src/lib/MSPUBParser97.cpp  |    3 +--
 src/lib/libmspub_utils.cpp |   32 ++++++++++++++++----------------
 src/lib/libmspub_utils.h   |    4 ++--
 5 files changed, 35 insertions(+), 39 deletions(-)

New commits:
commit 66bed1c2e93f606f51eacfe0f52b749c611408de
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 7 09:49:17 2017 +0100

    Use auto when declaring iterators and when initializing with a cast
    
    Change-Id: Ib5465f37b7302d01139f209013e6ea22c6fcdeb6

diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index af0e25f..65e432c 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -131,7 +131,7 @@ typedef boost::multi_array<TableLayoutCell, 2> TableLayout;
 
 void createTableLayout(const std::vector<CellInfo> &cells, TableLayout &tableLayout)
 {
-  for (std::vector<CellInfo>::const_iterator it = cells.begin(); it != cells.end(); ++it)
+  for (auto it = cells.begin(); it != cells.end(); ++it)
   {
     if ((it->m_endRow >= tableLayout.shape()[0]) || (it->m_endColumn >= tableLayout.shape()[1]))
     {
@@ -529,8 +529,7 @@ std::vector<int> MSPUBCollector::getShapeAdjustValues(const ShapeInfo &info) con
       ret.push_back(ptr_shape->mp_defaultAdjustValues[i]);
     }
   }
-  for (std::map<unsigned, int>::const_iterator i = info.m_adjustValuesByIndex.begin();
-       i != info.m_adjustValuesByIndex.end(); ++i)
+  for (auto i = info.m_adjustValuesByIndex.begin(); i != info.m_adjustValuesByIndex.end(); ++i)
   {
     unsigned index = i->first;
     int adjustVal = i->second;
@@ -620,8 +619,8 @@ std::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, cons
   librevenge::RVNGString fill = graphicsProps["draw:fill"] ? graphicsProps["draw:fill"]->getStr() : "none";
   bool hasFill = fill != "none";
   boost::optional<std::vector<TextParagraph> > maybeText = getShapeText(info);
-  bool hasText = bool(maybeText);
-  const bool isTable = bool(info.m_tableInfo);
+  auto hasText = bool(maybeText);
+  const auto isTable = bool(info.m_tableInfo);
   bool makeLayer = hasBorderArt ||
                    (hasStroke && hasFill) || (hasStroke && hasText) || (hasFill && hasText);
   if (makeLayer)
@@ -736,16 +735,14 @@ std::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, cons
       double width = coord.getWidthIn();
       double borderImgWidth =
         static_cast<double>(info.m_lines[0].m_widthInEmu) / EMUS_IN_INCH;
-      unsigned numImagesHoriz = static_cast<unsigned>(width / borderImgWidth);
-      unsigned numImagesVert = static_cast<unsigned>(height / borderImgWidth);
+      auto numImagesHoriz = static_cast<unsigned>(width / borderImgWidth);
+      auto numImagesVert = static_cast<unsigned>(height / borderImgWidth);
       double borderVertTotalPadding = height - numImagesVert * borderImgWidth;
       double borderHorizTotalPadding = width - numImagesHoriz * borderImgWidth;
       if (numImagesHoriz >= 2 && numImagesVert >= 2)
       {
-        unsigned numStretchedImagesVert = static_cast<unsigned>(
-                                            0.5 + (height - 2 * borderImgWidth) / borderImgWidth);
-        unsigned numStretchedImagesHoriz = static_cast<unsigned>(
-                                             0.5 + (width - 2 * borderImgWidth) / borderImgWidth);
+        auto numStretchedImagesVert = static_cast<unsigned>(0.5 + (height - 2 * borderImgWidth) / borderImgWidth);
+        auto numStretchedImagesHoriz = static_cast<unsigned>(0.5 + (width - 2 * borderImgWidth) / borderImgWidth);
         double stretchedImgHeight = stretch ?
                                     (height - 2 * borderImgWidth) / numStretchedImagesVert :
                                     borderImgWidth;
@@ -793,7 +790,7 @@ std::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, cons
             leftRectProps.insert("svg:height", height);
             leftRectProps.insert("svg:width", borderImgWidth);
             m_painter->drawRectangle(leftRectProps);
-            std::vector<unsigned>::const_iterator iOffset = ba.m_offsets.begin();
+            auto iOffset = ba.m_offsets.begin();
             boost::optional<Color> oneBitColor;
             if (bool(info.m_lineBackColor))
             {
@@ -1658,7 +1655,7 @@ void MSPUBCollector::writePage(unsigned pageSeqNum) const
   {
     m_painter->startPage(pageProps);
     boost::optional<unsigned> masterSeqNum = getMasterPageSeqNum(pageSeqNum);
-    bool hasMaster = bool(masterSeqNum);
+    auto hasMaster = bool(masterSeqNum);
     if (hasMaster)
     {
       writePageBackground(masterSeqNum.get());
@@ -1829,7 +1826,7 @@ void MSPUBCollector::setBorderImageOffset(unsigned index, unsigned offset)
   BorderArtInfo &bai = m_borderImages[index];
   bai.m_offsets.push_back(offset);
   bool added = false;
-  for (std::vector<unsigned>::iterator i = bai.m_offsetsOrdered.begin();
+  for (auto i = bai.m_offsetsOrdered.begin();
        i != bai.m_offsetsOrdered.end(); ++i)
   {
     if (*i >= offset)
diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index be9f9c1..7cf0d0b 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -1040,8 +1040,8 @@ bool MSPUBParser::parseQuill(librevenge::RVNGInputStream *input)
   {
     input->seek(textChunkReference->offset, librevenge::RVNG_SEEK_SET);
     unsigned bytesRead = 0;
-    std::vector<TextSpanReference>::iterator currentTextSpan = spans.begin();
-    std::vector<TextParagraphReference>::iterator currentTextPara = paras.begin();
+    auto currentTextSpan = spans.begin();
+    auto currentTextPara = paras.begin();
     for (unsigned j = 0; j < textIDs.size() && j < textLengths.size(); ++j)
     {
       MSPUB_DEBUG_MSG(("Parsing a text block.\n"));
@@ -1813,7 +1813,7 @@ void MSPUBParser::parseEscherShape(librevenge::RVNGInputStream *input, const Esc
             if ((shadowProps & FLAG_USE_FSHADOW) && (shadowProps & FLAG_USE_SHADOW))
             {
               unsigned *ptr_shadowType = getIfExists(foptValues.m_scalarValues, FIELDID_SHADOW_TYPE);
-              ShadowType shadowType = static_cast<ShadowType>(ptr_shadowType ? *ptr_shadowType : 0);
+              auto shadowType = static_cast<ShadowType>(ptr_shadowType ? *ptr_shadowType : 0);
               unsigned *shadowColor = getIfExists(foptValues.m_scalarValues, FIELDID_SHADOW_COLOR);
               unsigned *shadowHColor = getIfExists(foptValues.m_scalarValues, FIELDID_SHADOW_HIGHLIGHT);
               unsigned *shadowOpacity = getIfExists(foptValues.m_scalarValues, FIELDID_SHADOW_OPACITY);
@@ -1997,7 +1997,7 @@ std::shared_ptr<Fill> MSPUBParser::getNewFill(const std::map<unsigned short, uns
         {
           unsigned color = gradientData[offs] | (unsigned(gradientData[offs + 1]) << 8) | (unsigned(gradientData[offs + 2]) << 16) | (unsigned(gradientData[offs + 3]) << 24);
           offs += 4;
-          int posi = (int)(toFixedPoint(gradientData[offs] | (unsigned(gradientData[offs + 1]) << 8) | (unsigned(gradientData[offs + 2]) << 16) | (unsigned(gradientData[offs + 3]) << 24)) * 100);
+          auto posi = (int)(toFixedPoint(gradientData[offs] | (unsigned(gradientData[offs + 1]) << 8) | (unsigned(gradientData[offs + 2]) << 16) | (unsigned(gradientData[offs + 3]) << 24)) * 100);
           offs += 4;
           ColorReference sColor(color, color);
           if (fillFocus ==  0)
@@ -2307,7 +2307,7 @@ bool MSPUBParser::parseContentChunkReference(librevenge::RVNGInputStream *input,
 {
   //input should be at block.dataOffset + 4 , that is, at the beginning of the list of sub-blocks
   MSPUB_DEBUG_MSG(("Parsing chunk reference 0x%x\n", m_lastSeenSeqNum));
-  MSPUBContentChunkType type = (MSPUBContentChunkType)0;
+  auto type = (MSPUBContentChunkType)0;
   unsigned long offset = 0;
   unsigned parentSeqNum = 0;
   bool seenType = false;
diff --git a/src/lib/MSPUBParser97.cpp b/src/lib/MSPUBParser97.cpp
index 867a1cf..50ef91f 100644
--- a/src/lib/MSPUBParser97.cpp
+++ b/src/lib/MSPUBParser97.cpp
@@ -181,8 +181,7 @@ std::vector<MSPUBParser97::SpanInfo97> MSPUBParser97::getSpansInfo(
     {
       unsigned length = readU8(input);
       unsigned nextOffset = input->tell() + length;
-      unsigned char index = static_cast<unsigned char>(
-                              (input->tell() - 1 - offset) / 2);
+      auto index = static_cast<unsigned char>((input->tell() - 1 - offset) / 2);
       stylesByIndex[index] = readCharacterStyle(input, length);
       input->seek(nextOffset, librevenge::RVNG_SEEK_SET);
     }
diff --git a/src/lib/libmspub_utils.cpp b/src/lib/libmspub_utils.cpp
index c45b8eb..dc97423 100644
--- a/src/lib/libmspub_utils.cpp
+++ b/src/lib/libmspub_utils.cpp
@@ -275,17 +275,17 @@ uint8_t readU8(librevenge::RVNGInputStream *input)
 
 uint16_t readU16(librevenge::RVNGInputStream *input)
 {
-  uint16_t p0 = (uint16_t)readU8(input);
-  uint16_t p1 = (uint16_t)readU8(input);
+  auto p0 = (uint16_t)readU8(input);
+  auto p1 = (uint16_t)readU8(input);
   return (uint16_t)(p0|(p1<<8));
 }
 
 uint32_t readU32(librevenge::RVNGInputStream *input)
 {
-  uint32_t p0 = (uint32_t)readU8(input);
-  uint32_t p1 = (uint32_t)readU8(input);
-  uint32_t p2 = (uint32_t)readU8(input);
-  uint32_t p3 = (uint32_t)readU8(input);
+  auto p0 = (uint32_t)readU8(input);
+  auto p1 = (uint32_t)readU8(input);
+  auto p2 = (uint32_t)readU8(input);
+  auto p3 = (uint32_t)readU8(input);
   return (uint32_t)(p0|(p1<<8)|(p2<<16)|(p3<<24));
 }
 
@@ -306,14 +306,14 @@ int32_t readS32(librevenge::RVNGInputStream *input)
 
 uint64_t readU64(librevenge::RVNGInputStream *input)
 {
-  uint64_t p0 = (uint64_t)readU8(input);
-  uint64_t p1 = (uint64_t)readU8(input);
-  uint64_t p2 = (uint64_t)readU8(input);
-  uint64_t p3 = (uint64_t)readU8(input);
-  uint64_t p4 = (uint64_t)readU8(input);
-  uint64_t p5 = (uint64_t)readU8(input);
-  uint64_t p6 = (uint64_t)readU8(input);
-  uint64_t p7 = (uint64_t)readU8(input);
+  auto p0 = (uint64_t)readU8(input);
+  auto p1 = (uint64_t)readU8(input);
+  auto p2 = (uint64_t)readU8(input);
+  auto p3 = (uint64_t)readU8(input);
+  auto p4 = (uint64_t)readU8(input);
+  auto p5 = (uint64_t)readU8(input);
+  auto p6 = (uint64_t)readU8(input);
+  auto p7 = (uint64_t)readU8(input);
   return (uint64_t)(p0|(p1<<8)|(p2<<16)|(p3<<24)|(p4<<32)|(p5<<40)|(p6<<48)|(p7<<56));
 }
 
@@ -387,11 +387,11 @@ void appendCharacters(librevenge::RVNGString &text, const std::vector<unsigned c
   {
     // ICU documentation claims that character-by-character processing is faster "for small amounts of data" and "'normal' charsets"
     // (in any case, it is more convenient :) )
-    const char *src = (const char *)characters.data();
+    const auto *src = (const char *)characters.data();
     const char *srcLimit = (const char *)src + characters.size();
     while (src < srcLimit)
     {
-      uint32_t ucs4Character = (uint32_t)ucnv_getNextUChar(conv, &src, srcLimit, &status);
+      auto ucs4Character = (uint32_t)ucnv_getNextUChar(conv, &src, srcLimit, &status);
       if (U_SUCCESS(status))
       {
         _appendUCS4(text, ucs4Character);
diff --git a/src/lib/libmspub_utils.h b/src/lib/libmspub_utils.h
index e109b5d..8b30c9f 100644
--- a/src/lib/libmspub_utils.h
+++ b/src/lib/libmspub_utils.h
@@ -99,13 +99,13 @@ double doubleModulo(double x, double y);
 
 template <class MapT> typename MapT::mapped_type *getIfExists(MapT &map, const typename MapT::key_type &key)
 {
-  typename MapT::iterator i = map.find(key);
+  auto i = map.find(key);
   return i == map.end() ? nullptr : &(i->second);
 }
 
 template <class MapT> const typename MapT::mapped_type *getIfExists_const(MapT &map, const typename MapT::key_type &key)
 {
-  typename MapT::const_iterator i = map.find(key);
+  auto i = map.find(key);
   return i == map.end() ? nullptr : &(i->second);
 }
 


More information about the Libreoffice-commits mailing list