Skip to content

Commit 2cdaa84

Browse files
author
Chris Greening
committed
Fixes grouping of numeric files
1 parent 682e913 commit 2cdaa84

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

firmware/src/Files/Files.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ class DirectoryIterator
148148
return false; // Not a file or directory
149149
}
150150

151-
152151
std::string filename = entry->d_name;
153152
if (filename[0] == '.')
154153
{
155154
return false; // Hidden file
156155
}
157156

158157
std::string lowerCaseFilename = StringUtils::downcase(filename);
158+
// Note: We do not filter by first character here; bucketing for non-alphabetic is handled in getFileLetters.
159159
if (extensions.size() > 0)
160160
{
161161
bool validExtension = false;
@@ -177,10 +177,18 @@ class DirectoryIterator
177177
if (prefix != nullptr)
178178
{
179179
std::string lowerCasePrefix = StringUtils::downcase(prefix);
180-
if (lowerCaseFilename.length() < lowerCasePrefix.length() ||
181-
lowerCaseFilename.substr(0, lowerCasePrefix.length()) != lowerCasePrefix)
182-
{
183-
return false; // Prefix does not match
180+
char firstChar = filename.empty() ? '\0' : filename[0];
181+
if (lowerCasePrefix == "#") {
182+
// Match files whose first character is NOT an alphabetic letter
183+
if (std::isalpha(static_cast<unsigned char>(firstChar))) {
184+
return false;
185+
}
186+
} else {
187+
if (lowerCaseFilename.length() < lowerCasePrefix.length() ||
188+
lowerCaseFilename.substr(0, lowerCasePrefix.length()) != lowerCasePrefix)
189+
{
190+
return false; // Prefix does not match
191+
}
184192
}
185193
}
186194
return true; // Entry is valid
@@ -364,7 +372,13 @@ class FilesImplementation: public IFiles
364372
std::string lowerCaseFilename = StringUtils::downcase(filename);
365373
// get the first letter
366374
auto name = StringUtils::upcase(filename);
367-
auto letter = name.substr(0, 1);
375+
char firstChar = name.empty() ? '\0' : name[0];
376+
std::string letter;
377+
if (std::isalpha(static_cast<unsigned char>(firstChar))) {
378+
letter = name.substr(0, 1);
379+
} else {
380+
letter = "#";
381+
}
368382
if (fileCountByLetter.find(letter) == fileCountByLetter.end())
369383
{
370384
fileCountByLetter[letter] = 0;

0 commit comments

Comments
 (0)