1 | /* |
---|
2 | Copyright (C) 2018 Paul Brossier <piem@aubio.org> |
---|
3 | |
---|
4 | This file is part of aubio. |
---|
5 | |
---|
6 | aubio is free software: you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation, either version 3 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | aubio is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with aubio. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | |
---|
19 | */ |
---|
20 | |
---|
21 | #include "aubio_priv.h" |
---|
22 | |
---|
23 | #ifdef HAVE_WIN_HACKS |
---|
24 | #define strncasecmp _strnicmp |
---|
25 | #endif |
---|
26 | |
---|
27 | const char_t *aubio_str_get_extension(const char_t *filename) |
---|
28 | { |
---|
29 | // find last occurence of dot character |
---|
30 | const char_t *ext; |
---|
31 | if (!filename) return NULL; |
---|
32 | ext = strrchr(filename, '.'); |
---|
33 | if (!ext || ext == filename) return ""; |
---|
34 | else return ext + 1; |
---|
35 | } |
---|
36 | |
---|
37 | uint_t aubio_str_extension_matches(const char_t *ext, const char_t *pattern) |
---|
38 | { |
---|
39 | return ext && pattern && (strncasecmp(ext, pattern, PATH_MAX) == 0); |
---|
40 | } |
---|
41 | |
---|
42 | uint_t aubio_str_path_has_extension(const char_t *filename, |
---|
43 | const char_t *pattern) |
---|
44 | { |
---|
45 | const char_t *ext = aubio_str_get_extension(filename); |
---|
46 | return aubio_str_extension_matches(ext, pattern); |
---|
47 | } |
---|