issue 3598 and 2289 - util functions to determine file types by ending

This commit is contained in:
FelixJongleur42
2017-01-19 22:22:49 +01:00
committed by Flössie
parent c94e017d90
commit 62451f471f
7 changed files with 66 additions and 43 deletions

View File

@@ -224,6 +224,34 @@ void vflip (unsigned char* img, int w, int h)
delete [] flipped;
}
/**
* Return lower case extension without the "." or "" if the given name contains no "."
*/
Glib::ustring getFileExtension(const Glib::ustring &fname) {
// issue 3598 do not use casefold() to compare ignoring case - it seems to mangle sharp-s character and length of string
// simply get extension first, then use lowercase()
const Glib::ustring::size_type lastdot = fname.find_last_of ('.');
if( Glib::ustring::npos == lastdot ) {
return "";
}
return fname.substr(lastdot + 1).lowercase();
}
bool hasJpegExtension(const Glib::ustring &fname) {
const Glib::ustring extension = getFileExtension(fname);
return ((extension == "jpg") || (extension == "jpeg"));
}
bool hasTiffExtension(const Glib::ustring &fname) {
const Glib::ustring extension = getFileExtension(fname);
return ((extension == "tif") || (extension == "tiff"));
}
bool hasPngExtension(const Glib::ustring &fname) {
const Glib::ustring extension = getFileExtension(fname);
return (extension == "png");
}
}