Use range for loops to iterate const arrays
for (const TypeMapEntry &entry : typeMap) {
is much easier to read than
for (unsigned i = 0; i < sizeof(typeMap) / sizeof(typeMap[0]); i++) {
diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index c36a2d2..3955789 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -126,8 +126,8 @@
// recursively scan any resource dictionaries in objects in this
// resource dictionary
const char *resTypes[] = { "XObject", "Pattern" };
- for (unsigned int resType = 0; resType < sizeof(resTypes) / sizeof(resTypes[0]); ++resType) {
- Object objDict = resDict->lookup(resTypes[resType]);
+ for (const char *resType : resTypes) {
+ Object objDict = resDict->lookup(resType);
if (objDict.isDict()) {
for (int i = 0; i < objDict.dictGetLength(); ++i) {
Ref obj2Ref;
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index cdf8975..af3aa22 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -1796,8 +1796,8 @@
"Adobe-Japan2",
"Adobe-Korea1",
};
- for (size_t i = 0; i < sizeof(knownCollections)/sizeof(knownCollections[0]); i++) {
- if (collection->cmp(knownCollections[i]) == 0) {
+ for (const char *knownCollection : knownCollections) {
+ if (collection->cmp(knownCollection) == 0) {
error(errSyntaxError, -1, "Missing language pack for '{0:t}' mapping", collection);
return;
}
diff --git a/poppler/StructElement.cc b/poppler/StructElement.cc
index 19bac49..3ad314c 100644
--- a/poppler/StructElement.cc
+++ b/poppler/StructElement.cc
@@ -592,18 +592,18 @@
static inline const OwnerMapEntry *getOwnerMapEntry(Attribute::Owner owner)
{
- for (unsigned i = 0; i < sizeof(ownerMap) / sizeof(ownerMap[0]); i++) {
- if (owner == ownerMap[i].owner)
- return &ownerMap[i];
+ for (const OwnerMapEntry &entry : ownerMap) {
+ if (owner == entry.owner)
+ return &entry;
}
return nullptr;
}
static inline const OwnerMapEntry *getOwnerMapEntry(const char *name)
{
- for (unsigned i = 0; i < sizeof(ownerMap) / sizeof(ownerMap[0]); i++) {
- if (strcmp(name, ownerMap[i].name) == 0)
- return &ownerMap[i];
+ for (const OwnerMapEntry &entry : ownerMap) {
+ if (strcmp(name, entry.name) == 0)
+ return &entry;
}
return nullptr;
}
@@ -622,18 +622,18 @@
static inline const TypeMapEntry *getTypeMapEntry(StructElement::Type type)
{
- for (unsigned i = 0; i < sizeof(typeMap) / sizeof(typeMap[0]); i++) {
- if (type == typeMap[i].type)
- return &typeMap[i];
+ for (const TypeMapEntry &entry : typeMap) {
+ if (type == entry.type)
+ return &entry;
}
return nullptr;
}
static inline const TypeMapEntry *getTypeMapEntry(const char *name)
{
- for (unsigned i = 0; i < sizeof(typeMap) / sizeof(typeMap[0]); i++) {
- if (strcmp(name, typeMap[i].name) == 0)
- return &typeMap[i];
+ for (const TypeMapEntry &entry : typeMap) {
+ if (strcmp(name, entry.name) == 0)
+ return &entry;
}
return nullptr;
}
diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc
index 4021813..65ded8c 100644
--- a/poppler/TextOutputDev.cc
+++ b/poppler/TextOutputDev.cc
@@ -576,10 +576,9 @@
// returning combining versions of characters
static Unicode getCombiningChar(Unicode u) {
- int len = sizeof(combiningTable) / sizeof(combiningTable[0]);
- for (int i = 0; i < len; ++i) {
- if (u == combiningTable[i].base)
- return combiningTable[i].comb;
+ for (const CombiningTable &combining : combiningTable) {
+ if (u == combining.base)
+ return combining.comb;
}
return 0;
}