GOB: Make Util::setExtension() not add an extension to an empty string
This commit is contained in:
parent
eebd5a28f9
commit
cceaa04ef2
1 changed files with 8 additions and 0 deletions
|
@ -518,6 +518,11 @@ void Util::deleteList(List *list) {
|
|||
}
|
||||
|
||||
char *Util::setExtension(char *str, const char *ext) {
|
||||
assert(str && ext);
|
||||
|
||||
if (str[0] == '\0')
|
||||
return str;
|
||||
|
||||
char *dot = strrchr(str, '.');
|
||||
if (dot)
|
||||
*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) {
|
||||
if (str.empty())
|
||||
return str;
|
||||
|
||||
const char *dot = strrchr(str.c_str(), '.');
|
||||
if (dot)
|
||||
return Common::String(str.c_str(), dot - str.c_str()) + ext;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue