Skip to content

Commit 13e1d99

Browse files
committed
Simplification fixes
1 parent 87791a3 commit 13e1d99

2 files changed

Lines changed: 9 additions & 16 deletions

File tree

src/ResourceHost.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,13 @@ std::unique_ptr<Resource> ResourceHost::readFile(std::string const& path, struct
144144
*/
145145
std::unique_ptr<Resource> ResourceHost::readDirectory(std::string path, struct stat const& sb) {
146146
// Make the path end with a / (for consistency) if it doesnt already
147-
if (path.empty() || path[path.length() - 1] != '/')
147+
if (!path.ends_with('/'))
148148
path += "/";
149149

150150
// Probe for valid indexes
151-
uint32_t numIndexes = std::size(g_validIndexes);
152-
std::string loadIndex;
153-
struct stat sidx = {0};
154-
for (uint32_t i = 0; i < numIndexes; i++) {
155-
loadIndex = path + g_validIndexes[i];
151+
for (auto const& idx : g_validIndexes) {
152+
std::string loadIndex = path + idx;
153+
struct stat sidx = {0};
156154
// Found a suitable index file to load and return to the client
157155
if (stat(loadIndex.c_str(), &sidx) == 0)
158156
return readFile(loadIndex, sidx);

src/main.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,22 @@ int main()
4444
{
4545
// Parse config file
4646
std::map<std::string, std::string, std::less<>> config;
47-
std::fstream cfile;
48-
std::string line;
49-
std::string key;
50-
std::string val;
51-
int32_t epos = 0;
52-
cfile.open("server.config");
47+
std::ifstream cfile("server.config");
5348
if (!cfile.is_open()) {
5449
std::print("Unable to open server.config file in working directory\n");
5550
return -1;
5651
}
52+
std::string line;
5753
while (getline(cfile, line)) {
5854
// Skip empty lines or those beginning with a #
5955
if (line.length() == 0 || line.rfind("#", 0) == 0)
6056
continue;
6157

62-
epos = line.find("=");
63-
key = line.substr(0, epos);
64-
val = line.substr(epos + 1, line.length());
58+
size_t epos = line.find("=");
59+
std::string key = line.substr(0, epos);
60+
std::string val = line.substr(epos + 1, line.length());
6561
config.try_emplace(key, val);
6662
}
67-
cfile.close();
6863

6964
// Validate at least vhost, port, and diskpath are present
7065
if (!config.contains("vhost") || !config.contains("port") || !config.contains("diskpath")) {

0 commit comments

Comments
 (0)