GOB: Make Util::setExtension() not add an extension to an empty string

This commit is contained in:
Sven Hesse 2011-08-31 13:43:38 +02:00
parent eebd5a28f9
commit cceaa04ef2

View file

@ -518,6 +518,11 @@ void Util::deleteList(List *list) {
} }
char *Util::setExtension(char *str, const char *ext) { char *Util::setExtension(char *str, const char *ext) {
assert(str && ext);
if (str[0] == '\0')
return str;
char *dot = strrchr(str, '.'); char *dot = strrchr(str, '.');
if (dot) if (dot)
*dot = '\0'; *dot = '\0';
@ -527,6 +532,9 @@ char *Util::setExtension(char *str, const char *ext) {
} }
Common::String Util::setExtension(const Common::String &str, const Common::String &ext) { Common::String Util::setExtension(const Common::String &str, const Common::String &ext) {
if (str.empty())
return str;
const char *dot = strrchr(str.c_str(), '.'); const char *dot = strrchr(str.c_str(), '.');
if (dot) if (dot)
return Common::String(str.c_str(), dot - str.c_str()) + ext; return Common::String(str.c_str(), dot - str.c_str()) + ext;