diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_string_utils.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 18 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string_utils.c | 15 |
4 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 31b68204c51..99e86615e50 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -42,6 +42,8 @@ void BLI_split_dirfile( const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen); void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen); void BLI_split_file_part(const char *string, char *file, const size_t filelen); +const char *BLI_path_extension(const char *filepath) ATTR_NONNULL(); + void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__restrict file) ATTR_NONNULL(); void BLI_join_dirfile(char *__restrict string, diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h index 9740629276d..13dbb2de659 100644 --- a/source/blender/blenlib/BLI_string_utils.h +++ b/source/blender/blenlib/BLI_string_utils.h @@ -38,6 +38,7 @@ struct ListBase; typedef bool (*UniquenameCheckCallback)(void *arg, const char *name); size_t BLI_split_name_num(char *left, int *nr, const char *name, const char delim); +bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(); void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len); void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 111b530a527..18acbca00a1 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1685,6 +1685,24 @@ void BLI_split_file_part(const char *string, char *file, const size_t filelen) } /** + * Returns a pointer to the last extension (e.g. the position of the last period). + * Returns NULL if there is no extension. + */ +const char *BLI_path_extension(const char *filepath) +{ + const char *extension = strrchr(filepath, '.'); + if (extension == NULL) { + return NULL; + } + if (BLI_first_slash(extension) != NULL) { + /* There is a path separator in the extension, so the '.' was found in a + * directory component and not in the filename. */ + return NULL; + } + return extension; +} + +/** * Append a filename to a dir, ensuring slash separates. */ void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__restrict file) diff --git a/source/blender/blenlib/intern/string_utils.c b/source/blender/blenlib/intern/string_utils.c index f2b3ef2ad87..b956e1c0a7e 100644 --- a/source/blender/blenlib/intern/string_utils.c +++ b/source/blender/blenlib/intern/string_utils.c @@ -82,6 +82,21 @@ size_t BLI_split_name_num(char *left, int *nr, const char *name, const char deli return name_len; } +bool BLI_string_is_decimal(const char *string) +{ + if (*string == '\0') { + return false; + } + + /* Keep iterating over the string until a non-digit is found. */ + while (isdigit(*string)) { + string++; + } + + /* If the non-digit we found is the terminating \0, everything was digits. */ + return *string == '\0'; +} + static bool is_char_sep(const char c) { return ELEM(c, '.', ' ', '-', '_'); |