diff options
30 files changed, 107 insertions, 137 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9b17c0ef..8a07c3b6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,7 +40,7 @@ build_clang_libcpp: script: - git clone --branch ${CI_COMMIT_REF_NAME} --depth 1 ${TEST_DATA_URL} test-data || git clone --depth 1 ${UPSTREAM_TEST_DATA_URL} test-data - mkdir -p build && cd build - - CC=clang CXX=clang++ cmake -G Ninja -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DTESTDATADIR=$PWD/../test-data -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-header-filter=.;-checks=-*,performance-*,,bugprone-*,readability-inconsistent-declaration-parameter-name,readability-string-compare,modernize-deprecated-headers,modernize-make-unique,modernize-make-shared,modernize-use-override,modernize-use-equals-delete,modernize-use-emplace,modernize-use-bool-literals,modernize-redundant-void-arg,-bugprone-narrowing-conversions,-bugprone-macro-parentheses,-bugprone-suspicious-string-compare,-bugprone-incorrect-roundings,-bugprone-undefined-memory-manipulation;-warnings-as-errors=*" .. + - CC=clang CXX=clang++ cmake -G Ninja -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DTESTDATADIR=$PWD/../test-data -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-header-filter=.;-checks=-*,performance-*,bugprone-*,readability-inconsistent-declaration-parameter-name,readability-string-compare,modernize-deprecated-headers,modernize-make-unique,modernize-make-shared,modernize-use-override,modernize-use-equals-delete,modernize-use-emplace,modernize-use-bool-literals,modernize-redundant-void-arg,modernize-loop-convert,-bugprone-narrowing-conversions,-bugprone-macro-parentheses,-bugprone-suspicious-string-compare,-bugprone-incorrect-roundings,-bugprone-undefined-memory-manipulation;-warnings-as-errors=*" .. - ninja - ctest --output-on-failure diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp index 395802be..857bb6cc 100644 --- a/cpp/tests/poppler-dump.cpp +++ b/cpp/tests/poppler-dump.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2009-2010, Pino Toscano <pino@kde.org> - * Copyright (C) 2017, 2018, Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2017-2019, Albert Astals Cid <aacid@kde.org> * Copyright (C) 2017, Jason Alan Palmer <jalanpalmer@gmail.com> * Copyright (C) 2018, Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp> * Copyright (C) 2019, Masamichi Hosoda <trueroad@trueroad.jp> @@ -426,9 +426,9 @@ static void print_page_text_list(poppler::page *p) auto text_list = p->text_list(); std::cout << "---" << std::endl; - for (size_t i = 0; i < text_list.size(); i ++) { - poppler::rectf bbox = text_list[i].bbox(); - poppler::ustring ustr = text_list[i].text(); + for (const poppler::text_box &text : text_list) { + poppler::rectf bbox = text.bbox(); + poppler::ustring ustr = text.text(); std::cout << "[" << ustr << "] @ "; std::cout << "( x=" << bbox.x() << " y=" << bbox.y() << " w=" << bbox.width() << " h=" << bbox.height() << " )"; std::cout << std::endl; diff --git a/cpp/tests/poppler-render.cpp b/cpp/tests/poppler-render.cpp index ce0288f9..4264347d 100644 --- a/cpp/tests/poppler-render.cpp +++ b/cpp/tests/poppler-render.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2010, Pino Toscano <pino@kde.org> - * Copyright (C) 2017, Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2017, 2019, Albert Astals Cid <aacid@kde.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -65,8 +65,8 @@ int main(int argc, char *argv[]) if (show_formats) { const std::vector<std::string> formats = poppler::image::supported_image_formats(); std::cout << "Supported image formats:" << std::endl; - for (size_t i = 0; i < formats.size(); ++i) { - std::cout << " " << formats[i] << std::endl; + for (const std::string &format : formats) { + std::cout << " " << format << std::endl; } exit(0); } diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index 62169089..097c00df 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -588,8 +588,7 @@ build_ocg_state (PopplerDocument *document, return; } - for (std::size_t i = 0; i < st_list->size(); ++i) { - LinkOCGState::StateList *list = (*st_list)[i]; + for (const LinkOCGState::StateList *list : *st_list) { PopplerActionLayer *action_layer = g_slice_new0 (PopplerActionLayer); switch (list->st) { @@ -604,8 +603,7 @@ build_ocg_state (PopplerDocument *document, break; } - for (std::size_t j = 0; j < list->list->size(); ++j) { - Ref *ref = (*list->list)[j]; + for (Ref *ref : (*list->list)) { PopplerLayer *layer = get_layer_for_ref (document, document->layers, ref, preserve_rb); action_layer->layers = g_list_prepend (action_layer->layers, layer); diff --git a/glib/poppler-cached-file-loader.cc b/glib/poppler-cached-file-loader.cc index 2b4ed316..fe2fb350 100644 --- a/glib/poppler-cached-file-loader.cc +++ b/glib/poppler-cached-file-loader.cc @@ -88,10 +88,10 @@ int PopplerCachedFileLoader::load(const std::vector<ByteRange> &ranges, CachedFi return 0; size = 0; - for (size_t i = 0; i < ranges.size(); i++) { - bytesToRead = MIN(CachedFileChunkSize, ranges[i].length); + for (const ByteRange &range : ranges) { + bytesToRead = MIN(CachedFileChunkSize, range.length); rangeBytesRead = 0; - g_seekable_seek(G_SEEKABLE(inputStream), ranges[i].offset, G_SEEK_SET, cancellable, nullptr); + g_seekable_seek(G_SEEKABLE(inputStream), range.offset, G_SEEK_SET, cancellable, nullptr); do { bytesRead = g_input_stream_read(inputStream, buf, bytesToRead, cancellable, nullptr); if (bytesRead == -1) @@ -100,7 +100,7 @@ int PopplerCachedFileLoader::load(const std::vector<ByteRange> &ranges, CachedFi writer->write(buf, bytesRead); size += bytesRead; rangeBytesRead += bytesRead; - bytesToRead = ranges[i].length - rangeBytesRead; + bytesToRead = range.length - rangeBytesRead; } while (bytesRead > 0 && bytesToRead > 0); } diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index 06c7f7e1..319edc50 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -693,8 +693,7 @@ poppler_page_get_selection_region (PopplerPage *page, std::vector<PDFRectangle*>* list = text->getSelectionRegion(&poppler_selection, selection_style, scale); - for (std::size_t i = 0; i < list->size(); i++) { - PDFRectangle *selection_rect = (*list)[i]; + for (const PDFRectangle *selection_rect : *list) { PopplerRectangle *rect; rect = poppler_rectangle_new (); @@ -782,8 +781,7 @@ poppler_page_get_selected_region (PopplerPage *page, region = cairo_region_create (); - for (std::size_t i = 0; i < list->size(); i++) { - PDFRectangle *selection_rect = (*list)[i]; + for (const PDFRectangle *selection_rect : *list) { cairo_rectangle_int_t rect; rect.x = (gint) ((selection_rect->x1 * scale) + 0.5); @@ -2217,9 +2215,8 @@ poppler_page_get_text_layout_for_area (PopplerPage *page, { std::vector<TextWordSelection*> *line_words = word_list[i]; n_rects += line_words->size() - 1; - for (std::size_t j = 0; j < line_words->size(); j++) + for (const TextWordSelection *word_sel : *line_words) { - TextWordSelection *word_sel = (*line_words)[j]; n_rects += word_sel->getEnd() - word_sel->getBegin(); } } diff --git a/glib/poppler-structure-element.cc b/glib/poppler-structure-element.cc index 2a6f6970..a4faadd4 100644 --- a/glib/poppler-structure-element.cc +++ b/glib/poppler-structure-element.cc @@ -1152,8 +1152,8 @@ poppler_structure_element_get_text_spans (PopplerStructureElement *poppler_struc PopplerTextSpan **text_spans = g_new0 (PopplerTextSpan*, spans.size ()); size_t i = 0; - for (TextSpanArray::const_iterator s = spans.begin (); s != spans.end (); ++s) - text_spans[i++] = text_span_poppler_text_span (*s); + for (const TextSpan &s : spans) + text_spans[i++] = text_span_poppler_text_span (s); *n_text_spans = spans.size (); diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 40fe9b0d..37165e38 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -4230,8 +4230,8 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da // write the DA string if (daToks) { - for (int i = 0; i < (int)daToks->size(); ++i) { - appearBuf->append((*daToks)[i])->append(' '); + for (const GooString *daTok : *daToks) { + appearBuf->append(daTok)->append(' '); } } @@ -4421,8 +4421,8 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da // write the DA string if (daToks) { - for (std::size_t i = 0; i < daToks->size(); ++i) { - appearBuf->append((*daToks)[i])->append(' '); + for (const GooString *daTok : *daToks) { + appearBuf->append(daTok)->append(' '); } } @@ -4610,8 +4610,8 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con // write the DA string if (daToks) { - for (std::size_t k = 0; k < daToks->size(); ++k) { - appearBuf->append((*daToks)[k])->append(' '); + for (const GooString *daTok : *daToks) { + appearBuf->append(daTok)->append(' '); } } diff --git a/poppler/CachedFile.cc b/poppler/CachedFile.cc index bacbf16b..719bc2f4 100644 --- a/poppler/CachedFile.cc +++ b/poppler/CachedFile.cc @@ -96,13 +96,13 @@ int CachedFile::cache(const std::vector<ByteRange> &origRanges) for (int i = 0; i < numChunks; ++i) chunkNeeded[i] = false; - for (size_t i = 0; i < ranges->size(); i++) { + for (const ByteRange &r : *ranges) { - if ((*ranges)[i].length == 0) continue; - if ((*ranges)[i].offset >= length) continue; + if (r.length == 0) continue; + if (r.offset >= length) continue; - size_t start = (*ranges)[i].offset; - size_t end = start + (*ranges)[i].length - 1; + const size_t start = r.offset; + size_t end = start + r.length - 1; if (end >= length) end = length - 1; startChunk = start / CachedFileChunkSize; diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc index eb4c9a54..ba4ec060 100644 --- a/poppler/Catalog.cc +++ b/poppler/Catalog.cc @@ -278,8 +278,8 @@ bool Catalog::cachePageTree(int page) } bool loop = false;; - for (size_t i = 0; i < pagesRefList->size(); i++) { - if (((*pagesRefList)[i]).num == kidRef.getRefNum()) { + for (const Ref &pageRef : *pagesRefList) { + if (pageRef.num == kidRef.getRefNum()) { loop = true; break; } diff --git a/poppler/CurlCachedFile.cc b/poppler/CurlCachedFile.cc index a112ca23..c0c8a192 100644 --- a/poppler/CurlCachedFile.cc +++ b/poppler/CurlCachedFile.cc @@ -6,7 +6,7 @@ // // Copyright 2009 Stefan Thomas <thomas@eload24.com> // Copyright 2010, 2011 Hib Eris <hib@hiberis.nl> -// Copyright 2010 Albert Astals Cid <aacid@kde.org> +// Copyright 2010, 2019 Albert Astals Cid <aacid@kde.org> // //======================================================================== @@ -75,10 +75,10 @@ int CurlCachedFileLoader::load(const std::vector<ByteRange> &ranges, CachedFileW { CURLcode r = CURLE_OK; size_t fromByte, toByte; - for (size_t i = 0; i < ranges.size(); i++) { + for (const ByteRange &bRange : ranges) { - fromByte = ranges[i].offset; - toByte = fromByte + ranges[i].length - 1; + fromByte = bRange.offset; + toByte = fromByte + bRange.length - 1; GooString *range = GooString::format("{0:ud}-{1:ud}", fromByte, toByte); curl_easy_setopt(curl, CURLOPT_URL, url->c_str()); diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc index 965302a7..ccac72c0 100644 --- a/poppler/GfxFont.cc +++ b/poppler/GfxFont.cc @@ -1325,8 +1325,8 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA //----- get the character widths ----- // initialize all widths - for (int code = 0; code < 256; ++code) { - widths[code] = missingWidth * 0.001; + for (double &width : widths) { + width = missingWidth * 0.001; } // use widths from font dict, if present diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc index 5bf9c92a..2889d1e7 100644 --- a/poppler/GfxState.cc +++ b/poppler/GfxState.cc @@ -2916,8 +2916,7 @@ GfxColorSpace *GfxDeviceNColorSpace::copy() { auto sepsCSA = new std::vector<GfxSeparationColorSpace*>(); sepsCSA->reserve(sepsCS->size()); - for (std::size_t i = 0; i < sepsCS->size(); i++) { - GfxSeparationColorSpace *scs = (*sepsCS)[i]; + for (GfxSeparationColorSpace *scs : *sepsCS) { if (likely(scs != nullptr)) { sepsCSA->push_back((GfxSeparationColorSpace*)scs->copy()); } @@ -3105,8 +3104,7 @@ void GfxDeviceNColorSpace::createMapping(std::vector<GfxSeparationColorSpace*> * if (nComps == 1) sepFunc = func; else { - for (std::size_t k = 0; k < sepsCS->size(); k++) { - GfxSeparationColorSpace *sepCS = (*sepsCS)[k]; + for (GfxSeparationColorSpace *sepCS : *sepsCS) { if (!sepCS->getName()->cmp(names[i])) { sepFunc = sepCS->getFunc(); break; @@ -3145,8 +3143,7 @@ void GfxDeviceNColorSpace::createMapping(std::vector<GfxSeparationColorSpace*> * if (nComps == 1) separationList->push_back(new GfxSeparationColorSpace(new GooString(names[i]),alt->copy(), func->copy())); else { - for (std::size_t k = 0; k < sepsCS->size(); k++) { - GfxSeparationColorSpace *sepCS = (*sepsCS)[k]; + for (GfxSeparationColorSpace *sepCS : *sepsCS) { if (!sepCS->getName()->cmp(names[i])) { found = true; separationList->push_back((GfxSeparationColorSpace*)sepCS->copy()); diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc index 7b959210..9a2b92a9 100644 --- a/poppler/GlobalParams.cc +++ b/poppler/GlobalParams.cc @@ -263,7 +263,6 @@ SysFontList::~SysFontList() { SysFontInfo *SysFontList::find(const GooString *name, bool fixedWidth, bool exact) { GooString *name2; bool bold, italic, oblique; - SysFontInfo *fi; int n; name2 = name->copy(); @@ -340,9 +339,9 @@ SysFontInfo *SysFontList::find(const GooString *name, bool fixedWidth, bool exac } // search for the font - fi = nullptr; - for (std::size_t i = 0; i < fonts->size(); ++i) { - fi = (*fonts)[i]; + SysFontInfo *fi = nullptr; + for (SysFontInfo *f : *fonts) { + fi = f; if (fi->match(name2, bold, italic, oblique, fixedWidth)) { break; } @@ -350,8 +349,8 @@ SysFontInfo *SysFontList::find(const GooString *name, bool fixedWidth, bool exac } if (!fi && !exact && bold) { // try ignoring the bold flag - for (std::size_t i = 0; i < fonts->size(); ++i) { - fi = (*fonts)[i]; + for (SysFontInfo *f : *fonts) { + fi = f; if (fi->match(name2, false, italic)) { break; } @@ -360,8 +359,8 @@ SysFontInfo *SysFontList::find(const GooString *name, bool fixedWidth, bool exac } if (!fi && !exact && (bold || italic)) { // try ignoring the bold and italic flags - for (std::size_t i = 0; i < fonts->size(); ++i) { - fi = (*fonts)[i]; + for (SysFontInfo *f : *fonts) { + fi = f; if (fi->match(name2, false, false)) { break; } @@ -635,12 +634,11 @@ FILE *GlobalParams::findCMapFile(const GooString *collection, const GooString *c } FILE *GlobalParams::findToUnicodeFile(const GooString *name) { - GooString *dir, *fileName; + GooString *fileName; FILE *f; globalParamsLocker(); - for (std::size_t i = 0; i < toUnicodeDirs->size(); ++i) { - dir = (*toUnicodeDirs)[i]; + for (GooString *dir : *toUnicodeDirs) { fileName = appendToPath(dir->copy(), name->c_str()); f = openFile(fileName->c_str(), "r"); delete fileName; diff --git a/poppler/JBIG2Stream.cc b/poppler/JBIG2Stream.cc index 1e34bbd7..d7d84b49 100644 --- a/poppler/JBIG2Stream.cc +++ b/poppler/JBIG2Stream.cc @@ -4194,16 +4194,12 @@ void JBIG2Stream::readExtensionSeg(unsigned int length) { } JBIG2Segment *JBIG2Stream::findSegment(unsigned int segNum) { - JBIG2Segment *seg; - - for (std::size_t i = 0; i < globalSegments->size(); ++i) { - seg = (*globalSegments)[i]; + for (JBIG2Segment *seg : *globalSegments) { if (seg->getSegNum() == segNum) { return seg; } } - for (std::size_t i = 0; i < segments->size(); ++i) { - seg = (*segments)[i]; + for (JBIG2Segment *seg : *segments) { if (seg->getSegNum() == segNum) { return seg; } diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 4f3ce1c1..d3d93119 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -1326,8 +1326,7 @@ void PSOutputDev::postInit() } paperSizes = new std::vector<PSOutPaperSize*>(); - for (size_t pgi = 0; pgi < pages.size(); ++pgi) { - const int pg = pages[pgi]; + for (const int pg : pages) { Page *page = catalog->getPage(pg); if (page == nullptr) paperMatch = false; @@ -1673,8 +1672,7 @@ void PSOutputDev::writeDocSetup(Catalog *catalog, } else { writePS("xpdf begin\n"); } - for (size_t pgi = 0; pgi < pageList.size(); ++pgi) { - const int pg = pageList[pgi]; + for (const int pg : pageList) { page = doc->getPage(pg); if (!page) { error(errSyntaxError, -1, "Failed writing resources for page {0:d}", pg); diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc index 4dc8ad81..0ab8599e 100644 --- a/poppler/SplashOutputDev.cc +++ b/poppler/SplashOutputDev.cc @@ -1418,8 +1418,7 @@ void SplashOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA) { color[0] = color[1] = color[2] = color[3] = 0; break; case splashModeDeviceN8: - for (int i = 0; i < 4 + SPOT_NCOMPS; i++) - color[i] = 0; + splashClearColor(color); break; } splash->setStrokePattern(new SplashSolidColor(color)); diff --git a/poppler/StructElement.cc b/poppler/StructElement.cc index d0101c96..1b041208 100644 --- a/poppler/StructElement.cc +++ b/poppler/StructElement.cc @@ -829,8 +829,8 @@ StructElement::StructData::~StructData() delete id; delete title; delete language; - for (ElemPtrArray::iterator i = elements.begin(); i != elements.end(); ++i) delete *i; - for (AttrPtrArray::iterator i = attributes.begin(); i != attributes.end(); ++i) delete *i; + for (StructElement *element : elements) delete element; + for (Attribute *attribute : attributes) delete attribute; } @@ -975,8 +975,8 @@ GooString* StructElement::appendSubTreeText(GooString *string, bool recursive) c if (!string) string = new GooString(); - for (TextSpanArray::const_iterator i = spans.begin(); i != spans.end(); ++i) - string->append(i->getText()); + for (const TextSpan &span : spans) + string->append(span.getText()); return string; } diff --git a/poppler/StructTreeRoot.cc b/poppler/StructTreeRoot.cc index 8144db95..0c28e5ee 100644 --- a/poppler/StructTreeRoot.cc +++ b/poppler/StructTreeRoot.cc @@ -33,8 +33,8 @@ StructTreeRoot::StructTreeRoot(PDFDoc *docA, Dict *structTreeRootDict): StructTreeRoot::~StructTreeRoot() { - for (ElemPtrArray::iterator i = elements.begin(); i != elements.end(); ++i) - delete *i; + for (StructElement *element : elements) + delete element; } void StructTreeRoot::parse(Dict *root) diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc index b9e71561..6447eedd 100644 --- a/poppler/TextOutputDev.cc +++ b/poppler/TextOutputDev.cc @@ -2506,8 +2506,8 @@ void TextPage::updateFont(const GfxState *state) { // get the font info object curFont = nullptr; - for (std::size_t i = 0; i < fonts->size(); ++i) { - curFont = (*fonts)[i]; + for (TextFontInfo *f : *fonts) { + curFont = f; if (curFont->matches(state)) { break; } @@ -2824,8 +2824,6 @@ void TextPage::coalesce(bool physLayout, double fixedPitch, bool doHTML) { TextLine *line; TextBlock *blkList, *blk, *lastBlk, *blk0, *blk1, *blk2; TextFlow *flow, *lastFlow; - TextUnderline *underline; - TextLink *link; int rot, poolMinBaseIdx, baseIdx, startBaseIdx, endBaseIdx; double minBase, maxBase, newMinBase, newMaxBase; double fontSize, colSpace1, colSpace2, lineSpace, intraLineSpace, blkSpace; @@ -2878,8 +2876,7 @@ void TextPage::coalesce(bool physLayout, double fixedPitch, bool doHTML) { if (doHTML) { //----- handle underlining - for (std::size_t i = 0; i < underlines->size(); ++i) { - underline = (*underlines)[i]; + for (const TextUnderline *underline : *underlines) { if (underline->horiz) { // rot = 0 if (pools[0]->minBaseIdx <= pools[0]->maxBaseIdx) { @@ -2941,9 +2938,7 @@ void TextPage::coalesce(bool physLayout, double fixedPitch, bool doHTML) { } //----- handle links - for (std::size_t i = 0; i < links->size(); ++i) { - link = (*links)[i]; - + for (const TextLink *link : *links) { // rot = 0 if (pools[0]->minBaseIdx <= pools[0]->maxBaseIdx) { startBaseIdx = pools[0]->getBaseIdx(link->yMin); @@ -4786,8 +4781,7 @@ void TextSelectionPainter::endPage() state->setFillColor(glyph_color); out->updateFillColor(state); - for (std::size_t i = 0; i < selectionList->size(); i++) { - TextWordSelection *sel = (*selectionList)[i]; + for (const TextWordSelection *sel : *selectionList) { int begin = sel->begin; while (begin < sel->end) { diff --git a/poppler/XRef.cc b/poppler/XRef.cc index 1191ed3d..8f9dd7fe 100644 --- a/poppler/XRef.cc +++ b/poppler/XRef.cc @@ -1518,8 +1518,8 @@ void XRef::readXRefUntil(int untilEntryNum, std::vector<int> *xrefStreamObjsNum) std::vector<Goffset> followedPrev; while (prevXRefOffset && (untilEntryNum == -1 || (untilEntryNum < size && entries[untilEntryNum].type == xrefEntryNone))) { bool followed = false; - for (size_t j = 0; j < followedPrev.size(); j++) { - if (followedPrev.at(j) == prevXRefOffset) { + for (long long j : followedPrev) { + if (j == prevXRefOffset) { followed = true; break; } @@ -1682,8 +1682,7 @@ void XRef::scanSpecialFlags() { } // Mark XRef streams objects as Unencrypted and DontRewrite - for (size_t i = 0; i < xrefStreamObjNums.size(); ++i) { - const int objNum = xrefStreamObjNums.at(i); + for (const int objNum : xrefStreamObjNums) { getEntry(objNum)->setFlag(XRefEntry::Unencrypted, true); getEntry(objNum)->setFlag(XRefEntry::DontRewrite, true); } diff --git a/qt5/src/poppler-optcontent.cc b/qt5/src/poppler-optcontent.cc index 56abf871..1a659bf6 100644 --- a/qt5/src/poppler-optcontent.cc +++ b/qt5/src/poppler-optcontent.cc @@ -39,6 +39,9 @@ namespace Poppler { + // TODO use qAsConst when we can depend on Qt 5.7 + // or std::as_const when we can depend on C++17 + template <class T> constexpr std::add_const_t<T>& as_const(T& t) noexcept { return t; } RadioButtonGroup::RadioButtonGroup( OptContentModelPrivate *ocModel, Array *rbarray ) { @@ -51,8 +54,7 @@ namespace Poppler OptContentItem *item = ocModel->itemFromRef( QString::number(ref.getRefNum() ) ); itemsInGroup.append( item ); } - for (int i = 0; i < itemsInGroup.size(); ++i) { - OptContentItem *item = itemsInGroup.at(i); + for (OptContentItem *item : as_const(itemsInGroup)) { item->appendRBGroup( this ); } } @@ -64,8 +66,7 @@ namespace Poppler QSet<OptContentItem *> RadioButtonGroup::setItemOn( OptContentItem *itemToSetOn ) { QSet<OptContentItem *> changedItems; - for (int i = 0; i < itemsInGroup.size(); ++i) { - OptContentItem *thisItem = itemsInGroup.at(i); + for (OptContentItem *thisItem : as_const(itemsInGroup)) { if (thisItem != itemToSetOn) { QSet<OptContentItem *> newChangedItems; thisItem->setState(OptContentItem::Off, false /*obeyRadioGroups*/, newChangedItems); @@ -137,8 +138,7 @@ namespace Poppler if ( state == OptContentItem::On ) { m_group->setState( OptionalContentGroup::On ); if (obeyRadioGroups) { - for (int i = 0; i < m_rbGroups.size(); ++i) { - RadioButtonGroup *rbgroup = m_rbGroups.at(i); + for (RadioButtonGroup *rbgroup : as_const(m_rbGroups)) { changedItems += rbgroup->setItemOn( this ); } } @@ -402,12 +402,9 @@ namespace Poppler QSet<OptContentItem *> changedItems; const std::vector<::LinkOCGState::StateList*> *statesList = popplerLinkOCGState->getStateList(); - for (std::size_t i = 0; i < statesList->size(); ++i) { - ::LinkOCGState::StateList *stateList = (*statesList)[i]; - - std::vector<Ref*> *refsList = stateList->list; - for (std::size_t j = 0; j < refsList->size(); ++j) { - Ref *ref = (*refsList)[j]; + for (const ::LinkOCGState::StateList *stateList : *statesList) { + const std::vector<Ref*> *refsList = stateList->list; + for (const Ref *ref : *refsList) { OptContentItem *item = d->itemFromRef(QString::number(ref->num)); if (stateList->st == ::LinkOCGState::On) { diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index 7341f419..c9987761 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -364,9 +364,9 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo if ( nextActions ) { QVector<Link *> links; - for ( std::size_t i = 0; i < nextActions->size(); ++i ) + for ( ::LinkAction *nextAction : *nextActions ) { - links << convertLinkActionToLink( (*nextActions)[ i ], parentDoc, linkArea ); + links << convertLinkActionToLink( nextAction, parentDoc, linkArea ); } LinkPrivate::get(popplerLink)->nextLinks = links; } diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc index 74dbe960..3c9bf512 100644 --- a/qt5/src/poppler-private.cc +++ b/qt5/src/poppler-private.cc @@ -274,10 +274,9 @@ namespace Debug { void DocumentData::addTocChildren( QDomDocument * docSyn, QDomNode * parent, const std::vector<::OutlineItem*> * items ) { - for ( std::size_t i = 0; i < items->size(); ++i ) + for ( ::OutlineItem * outlineItem : *items ) { // iterate over every object in 'items' - ::OutlineItem * outlineItem = (*items)[ i ]; // 1. create element using outlineItem's title as tagName QString name; diff --git a/splash/Splash.cc b/splash/Splash.cc index d66a9c16..38fd5a7a 100644 --- a/splash/Splash.cc +++ b/splash/Splash.cc @@ -4520,8 +4520,8 @@ void Splash::scaleImageYdXu(SplashImageSource src, void *srcData, break; case splashModeDeviceN8: for (i = 0; i < xStep; ++i) { - for (int cp = 0; cp < SPOT_NCOMPS+4; cp++) - *destPtr++ = (unsigned char)pix[cp]; + for (unsigned int cp : pix) + *destPtr++ = (unsigned char)cp; } break; } @@ -4672,8 +4672,8 @@ void Splash::scaleImageYuXd(SplashImageSource src, void *srcData, case splashModeDeviceN8: for (i = 0; i < yStep; ++i) { destPtr = destPtr0 + (i * scaledWidth + x) * nComps; - for (int cp = 0; cp < SPOT_NCOMPS+4; cp++) - *destPtr++ = (unsigned char)pix[cp]; + for (unsigned int cp : pix) + *destPtr++ = (unsigned char)cp; } break; } @@ -4826,8 +4826,8 @@ void Splash::scaleImageYuXu(SplashImageSource src, void *srcData, for (i = 0; i < yStep; ++i) { for (j = 0; j < xStep; ++j) { destPtr = destPtr0 + (i * scaledWidth + xx + j) * nComps; - for (int cp = 0; cp < SPOT_NCOMPS+4; cp++) - *destPtr++ = (unsigned char)pix[cp]; + for (unsigned int cp : pix) + *destPtr++ = (unsigned char)cp; } } break; @@ -4977,8 +4977,8 @@ void Splash::scaleImageYuXuBilinear(SplashImageSource src, void *srcData, *destPtr++ = (unsigned char)pix[3]; break; case splashModeDeviceN8: - for (int cp = 0; cp < SPOT_NCOMPS+4; cp++) - *destPtr++ = (unsigned char)pix[cp]; + for (unsigned int cp : pix) + *destPtr++ = (unsigned char)cp; break; } diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc index 1dc158b4..e4522f62 100644 --- a/splash/SplashBitmap.cc +++ b/splash/SplashBitmap.cc @@ -124,8 +124,8 @@ SplashBitmap::SplashBitmap(int widthA, int heightA, int rowPadA, } separationList = new std::vector<GfxSeparationColorSpace*>(); if (separationListA != nullptr) - for (std::size_t i = 0; i < separationListA->size(); i++) - separationList->push_back((GfxSeparationColorSpace*)( (*separationListA)[i])->copy()); + for (GfxSeparationColorSpace *separation : *separationListA) + separationList->push_back((GfxSeparationColorSpace*)separation->copy()); } SplashBitmap *SplashBitmap::copy(SplashBitmap *src) { diff --git a/splash/SplashState.cc b/splash/SplashState.cc index 9bdb099b..bb734481 100644 --- a/splash/SplashState.cc +++ b/splash/SplashState.cc @@ -13,6 +13,7 @@ // // Copyright (C) 2009, 2011, 2012, 2015 Thomas Freitag <Thomas.Freitag@alfa.de> // Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com> +// Copyright (C) 2019 Albert Astals Cid <aacid@kde.org> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -81,8 +82,9 @@ SplashState::SplashState(int width, int height, bool vectorAntialias, cmykTransferM[i] = (unsigned char)i; cmykTransferY[i] = (unsigned char)i; cmykTransferK[i] = (unsigned char)i; - for (int cp = 0; cp < SPOT_NCOMPS+4; cp++) - deviceNTransfer[cp][i] = (unsigned char)i; + for (auto &cp : deviceNTransfer) { + cp[i] = (unsigned char)i; + } } overprintMask = 0xffffffff; overprintAdditive = false; @@ -132,8 +134,9 @@ SplashState::SplashState(int width, int height, bool vectorAntialias, cmykTransferM[i] = (unsigned char)i; cmykTransferY[i] = (unsigned char)i; cmykTransferK[i] = (unsigned char)i; - for (int cp = 0; cp < SPOT_NCOMPS+4; cp++) - deviceNTransfer[cp][i] = (unsigned char)i; + for (auto &cp : deviceNTransfer) { + cp[i] = (unsigned char)i; + } } overprintMask = 0xffffffff; overprintAdditive = false; diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc index c5e1ec1d..dfc818cf 100644 --- a/utils/HtmlOutputDev.cc +++ b/utils/HtmlOutputDev.cc @@ -1009,7 +1009,7 @@ HtmlMetaVar::~HtmlMetaVar() delete content; } -GooString* HtmlMetaVar::toString() +GooString* HtmlMetaVar::toString() { GooString *result = new GooString("<meta name=\""); result->append(name); @@ -1659,10 +1659,9 @@ void HtmlOutputDev::dumpMetaVars(FILE *file) { GooString *var; - for(std::size_t i = 0; i < glMetaVars->size(); i++) + for(HtmlMetaVar *t : *glMetaVars) { - HtmlMetaVar *t = (*glMetaVars)[i]; - var = t->toString(); + var = t->toString(); fprintf(file, "%s\n", var->c_str()); delete var; } @@ -1747,9 +1746,8 @@ bool HtmlOutputDev::newHtmlOutlineLevel(FILE *output, const std::vector<OutlineI } fputs("<ul>\n",output); - for (std::size_t i = 0; i < outlines->size(); i++) + for (OutlineItem *item : *outlines) { - OutlineItem *item = (*outlines)[i]; GooString *titleStr = HtmlFont::HtmlFilter(item->getTitle(), item->getTitleLength()); @@ -1806,9 +1804,8 @@ void HtmlOutputDev::newXmlOutlineLevel(FILE *output, const std::vector<OutlineIt { fputs("<outline>\n", output); - for (std::size_t i = 0; i < outlines->size(); i++) + for (OutlineItem *item : *outlines) { - OutlineItem *item = (*outlines)[i]; GooString *titleStr = HtmlFont::HtmlFilter(item->getTitle(), item->getTitleLength()); const int itemPage = getOutlinePageNum(item); diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc index aad7d8bb..6a6acacb 100644 --- a/utils/pdftoppm.cc +++ b/utils/pdftoppm.cc @@ -18,7 +18,7 @@ // Copyright (C) 2009 Michael K. Johnson <a1237@danlj.org> // Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com> // Copyright (C) 2009 Stefan Thomas <thomas@eload24.com> -// Copyright (C) 2009-2011, 2015, 2018 Albert Astals Cid <aacid@kde.org> +// Copyright (C) 2009-2011, 2015, 2018, 2019 Albert Astals Cid <aacid@kde.org> // Copyright (C) 2010, 2012, 2017 Adrian Johnson <ajohnson@redneon.com> // Copyright (C) 2010 Hib Eris <hib@hiberis.nl> // Copyright (C) 2010 Jonathan Liu <net147@gmail.com> @@ -521,8 +521,7 @@ int main(int argc, char *argv[]) { // write PPM files if (jpegcmyk || overprint) { globalParams->setOverprintPreview(true); - for (int cp = 0; cp < SPOT_NCOMPS+4; cp++) - paperColor[cp] = 0; + splashClearColor(paperColor); } else { paperColor[0] = 255; paperColor[1] = 255; diff --git a/utils/printencodings.cc b/utils/printencodings.cc index 85c365ec..15580de6 100644 --- a/utils/printencodings.cc +++ b/utils/printencodings.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2008, 2019, Albert Astals Cid <aacid@kde.org> * Copyright (C) 2017, Adrian Johnson <ajohnson@redneon.com> * Copyright (C) 2018, Adam Reichold <adam.reichold@t-online.de> * Copyright (C) 2019, Oliver Sander <oliver.sander@tu-dresden.de> @@ -35,8 +35,7 @@ void printEncodings() }); printf("Available encodings are:\n"); - for (std::size_t i = 0; i < encNames->size(); ++i) { - GooString *enc = (*encNames)[i]; + for (const GooString *enc : *encNames) { printf("%s\n", enc->c_str()); } |