Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant boolean literal in conditional return statement and code cleanup #117

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/hello_imgui/impl/runner_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,41 @@ namespace HelloImGui
auto _stringToSaneFilename=[](const std::string& s, const std::string& extension) -> std::string
{
std::string filenameSanitized;

for (char c : s)
{
if (isalnum(c))
filenameSanitized += c;
else
filenameSanitized += "_";
}

filenameSanitized += extension;
return filenameSanitized;
};

if (! runnerParams.iniFilename.empty())
return runnerParams.iniFilename;
else
{
if (runnerParams.iniFilename_useAppWindowTitle && !runnerParams.appWindowParams.windowTitle.empty())
{
std::string iniFilenameSanitized = _stringToSaneFilename(runnerParams.appWindowParams.windowTitle, ".ini");
return iniFilenameSanitized;
}
else
return "imgui.ini";
}

if (runnerParams.iniFilename_useAppWindowTitle && !runnerParams.appWindowParams.windowTitle.empty())
return _stringToSaneFilename(runnerParams.appWindowParams.windowTitle, ".ini");

return "imgui.ini";

};

auto mkdirToFilename = [](const std::string& filename) -> bool
{
std::filesystem::path p(filename);
std::filesystem::path dir = p.parent_path();

if (dir.empty())
return true;

if (std::filesystem::exists(dir))
{
if (std::filesystem::is_directory(dir) || std::filesystem::is_symlink(dir))
return true;
else
return false;
}
else
pthom marked this conversation as resolved.
Show resolved Hide resolved
return std::filesystem::create_directories(dir);
return std::filesystem::is_directory(dir) || std::filesystem::is_symlink(dir);

return std::filesystem::create_directories(dir);
};


Expand All @@ -87,10 +84,13 @@ namespace HelloImGui
void DeleteIniSettings(const RunnerParams& runnerParams)
{
std::string iniFullFilename = IniSettingsLocation(runnerParams);

if (iniFullFilename.empty())
return;

if (!std::filesystem::exists(iniFullFilename))
return;

bool success = std::filesystem::remove(iniFullFilename);
IM_ASSERT(success && "Failed to delete ini file %s");
}
Expand All @@ -99,8 +99,10 @@ namespace HelloImGui
bool HasIniSettings(const RunnerParams& runnerParams)
{
std::string iniFullFilename = IniSettingsLocation(runnerParams);

if (iniFullFilename.empty())
return false;

return std::filesystem::exists(iniFullFilename);
}

Expand Down
Loading