mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 18:01:15 +00:00
Rewrite QFS_StripExtension() to use QFS_FileExtension().
This commit is contained in:
parent
96ef0ffaea
commit
225f1cd06c
2 changed files with 30 additions and 2 deletions
|
@ -1330,8 +1330,8 @@ QFS_StripExtension (const char *in, char *out)
|
|||
if (out != in)
|
||||
strcpy (out, in);
|
||||
|
||||
if ((tmp = strrchr (out, '.')))
|
||||
*tmp = 0;
|
||||
tmp = out + (QFS_FileExtension (out) - out);
|
||||
*tmp = 0;
|
||||
}
|
||||
|
||||
VISIBLE const char *
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "QF/quakefs.h"
|
||||
|
||||
|
@ -46,6 +47,22 @@ struct {
|
|||
};
|
||||
#define num_ext_tests (sizeof (ext_tests) / sizeof (ext_tests[0]))
|
||||
|
||||
struct {
|
||||
const char *path;
|
||||
const char *expect;
|
||||
} strip_tests[] = {
|
||||
{"foo", "foo"},
|
||||
{"foo.a", "foo"},
|
||||
{"foo.a.b", "foo.a"},
|
||||
{".foo", ".foo"},
|
||||
{"bar/foo", "bar/foo"},
|
||||
{"bar/foo.a", "bar/foo"},
|
||||
{"bar/foo.a.b", "bar/foo.a"},
|
||||
{"bar/.foo", "bar/.foo"},
|
||||
{"bar.a/foo", "bar.a/foo"},
|
||||
};
|
||||
#define num_strip_tests (sizeof (strip_tests) / sizeof (strip_tests[0]))
|
||||
|
||||
int
|
||||
main (int argc, const char **argv)
|
||||
{
|
||||
|
@ -71,5 +88,16 @@ main (int argc, const char **argv)
|
|||
res = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < num_strip_tests; i++) {
|
||||
char *strip = strdup (strip_tests[i].path);
|
||||
QFS_StripExtension (strip, strip);
|
||||
if (strcmp (strip, strip_tests[i].expect)) {
|
||||
fprintf (stderr, "FAIL: (%zd) \"%s\" -> \"%s\", got \"%s\"\n", i,
|
||||
strip_tests[i].path, strip_tests[i].expect, strip);
|
||||
res = 1;
|
||||
}
|
||||
free (strip);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue