ExtractFileBase stops on first dot instead of last

Is there something that doesn't work right in the latest GZDoom? Post about it here.

Moderator: GZDoom Developers

Forum rules
Please construct and post a simple demo whenever possible for all bug reports. Please provide links to everything.

If you can include a wad demonstrating the problem, please do so. Bug reports that include fully-constructed demos have a much better chance of being investigated in a timely manner than those that don't.

Please make a new topic for every bug. Don't combine multiple bugs into a single topic. Thanks!

ExtractFileBase stops on first dot instead of last

Postby wrkq » Sat Dec 26, 2020 8:21 pm

I was reminded of this quirk today due to someone asking how to switch soundfonts, and checked the code to see why. :)

If the common helper function ExtractFileBase from cmdlib.cpp is told to not include extension, it searches for a dot from left to right.

So calling
ExtractFileBase( "x:\path\to\gzdoom\soundfonts\Some Soundfont V3.5c by Author.sf2",false)
will return "Some Soundfont V3" instead of "Some Soundfont V3.5c by Author".

That truncated name will show up in the soundfont selection menu.

Of course same behavior will occur in any other use of ExtractFileBase.
I don't know, but maybe in some cases it may even cause some kind of conflicts/mixups (two filenames differing only on the part after first dot).

Also worth noting that the function StripExtension() available right below in cmdlib.cpp does the right thing, searching from the right.
So StripExtension(ExtractFileBase("path",true)) is not equivalent to ExtractFileBase("path",false).
wrkq
 
Joined: 02 Apr 2016

Return to Bugs

Who is online

Users browsing this forum: No registered users and 0 guests