ExtractFileBase stops on first dot instead of last

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).