Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-01-30 20:09:01 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-01-30 20:30:05 +0400
commit3c86a1932f848f694ba3a88bb1af35325f3f89a2 (patch)
tree2b2fa7c9ea70436f5e650673c12300290dfd0f34 /source/blender/blenlib/intern/path_util.c
parent0cb49286ce45f1b2ce16db0e174170ef2a671dba (diff)
Code cleanup: add BLI_testextensie_n, replacing multuple calls to BLI_testextensie
also use attributes for BLI path functions
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r--source/blender/blenlib/intern/path_util.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 422440d8b09..58ff67aa612 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1543,20 +1543,53 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c
BLI_clean(string);
}
+static bool testextensie_ex(const char *str, const size_t str_len,
+ const char *ext, const size_t ext_len)
+{
+ BLI_assert(strlen(str) == str_len);
+ BLI_assert(strlen(ext) == ext_len);
+
+ return (((str_len == 0 || ext_len == 0 || ext_len >= str_len) == 0) &&
+ (BLI_strcasecmp(ext, str + str_len - ext_len) == 0));
+}
+
/* does str end with ext. */
bool BLI_testextensie(const char *str, const char *ext)
{
- const size_t a = strlen(str);
- const size_t b = strlen(ext);
- return !(a == 0 || b == 0 || b >= a) && (BLI_strcasecmp(ext, str + a - b) == 0);
+ return testextensie_ex(str, strlen(str), ext, strlen(ext));
+}
+
+bool BLI_testextensie_n(const char *str, ...)
+{
+ const size_t str_len = strlen(str);
+
+ va_list args;
+ const char *ext;
+ bool ret = false;
+
+ va_start(args, str);
+
+ while ((ext = (const char *) va_arg(args, void *))) {
+ if (testextensie_ex(str, str_len, ext, strlen(ext))) {
+ ret = true;
+ goto finally;
+ }
+ }
+
+finally:
+ va_end(args);
+
+ return ret;
}
/* does str end with any of the suffixes in *ext_array. */
bool BLI_testextensie_array(const char *str, const char **ext_array)
{
+ const size_t str_len = strlen(str);
int i = 0;
+
while (ext_array[i]) {
- if (BLI_testextensie(str, ext_array[i])) {
+ if (testextensie_ex(str, str_len, ext_array[i], strlen(ext_array[i]))) {
return true;
}