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

Fix buggy get/remove file extension #65

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
24 changes: 13 additions & 11 deletions crnlib/crn_file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,16 @@ bool file_utils::full_path(dynamic_string& path) {
}

bool file_utils::get_extension(dynamic_string& filename) {
int sep = -1;
#ifdef WIN32
sep = filename.find_right('\\');
int sep = filename.find_right('/');

#ifdef _WIN32
int sep2 = filename.find_right('\\');
if (sep2 > sep)
sep = sep2;
#endif
if (sep < 0)
sep = filename.find_right('/');

int dot = filename.find_right('.');
if (dot < sep) {
if (dot <= sep) {
filename.clear();
return false;
}
Expand All @@ -392,12 +393,13 @@ bool file_utils::get_extension(dynamic_string& filename) {
}

bool file_utils::remove_extension(dynamic_string& filename) {
int sep = -1;
#ifdef WIN32
sep = filename.find_right('\\');
int sep = filename.find_right('/');

#ifdef _WIN32
int sep2 = filename.find_right('\\');
if (sep2 > sep)
sep = sep2;
#endif
if (sep < 0)
sep = filename.find_right('/');

int dot = filename.find_right('.');
if (dot < sep)
Expand Down