comparison src/dmstring.c @ 2079:9b6027d51f76

Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 10 Dec 2018 19:24:45 +0200
parents eeddaf411083
children 63dd0a611586
comparison
equal deleted inserted replaced
2078:b2f1ce24f81b 2079:9b6027d51f76
1 #include "dmlib.h" 1 #include "dmlib.h"
2 #include <stdarg.h> 2 #include <stdarg.h>
3
4
5 /* Returns the filename and path without the last filename extension,
6 * E.g. everything before the last '.', if any.
7 */
8 char *dm_basefilename(const char *filename)
9 {
10 char *tmp, *fext;
11
12 if (filename == NULL ||
13 (tmp = dm_strdup(filename)) == NULL)
14 return NULL;
15
16 if ((fext = strrchr(tmp, '.')) != NULL)
17 {
18 char *fpath = strrchr(tmp, DM_DIR_SEPARATOR);
19 if (fpath == NULL || (fpath != NULL && fext > fpath))
20 *fext = 0;
21 }
22
23 return tmp;
24 }
25
26
27 /* Replace filename extension based on format pattern.
28 * Usage: res = dm_strdup_fext(orig_filename, "foo_%s.cmp");
29 */
30 char *dm_strdup_fext(const char *filename, const char *fmt)
31 {
32 char *result, *tmp;
33
34 if ((tmp = dm_basefilename(filename)) == NULL)
35 return NULL;
36
37 result = dm_strdup_printf(fmt, tmp);
38
39 dmFree(tmp);
40
41 return result;
42 }
43 3
44 4
45 /* Compare two strings ignoring case [strcasecmp, strncasecmp] 5 /* Compare two strings ignoring case [strcasecmp, strncasecmp]
46 */ 6 */
47 int dm_strcasecmp(const char *haystack, const char *needle) 7 int dm_strcasecmp(const char *haystack, const char *needle)