diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2019-03-20 14:59:11 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2019-03-20 15:42:45 +0300 |
commit | 0333cf00baf4d5b796347334af1f15d5bb9a2df4 (patch) | |
tree | 10d17ce16e34bd955f7a7ad7400a3dabed6e17dc /source/blender/blenlib/intern/path_util.c | |
parent | 8b9b3422eb1528339173142976e04544979f15e5 (diff) |
Fix BLI_path_frame_strip
The `BLI_path_frame_strip` function was completely broken, unless the
number of digits in the sequence number was the same as the length of
the extension. In other words, it would work fine for `file.0001.abc` (4
digit `0001` and 4 char `.abc`), but other combinations would truncate
to the shortest (`file.001.abc` would become `file.###.ab` and
`file.00001.a` would become `file.##.a`). The dependency between the
sequence number and the file extension is now removed.
The behaviour has changed a little bit in the case where there are no
numbers in the filename. Previously, `path="filename.abc"` would result
in `path="filename.abc"` and `ext=""`, but now it results in
`path="filename"` and `ext=".abc"`. This way `ext` always contains the
extension, and the behaviour is consistent regardless of whether there
were any numbers found.
Furthermore, I've removed the `bool set_frame_char` parameter, because
it was unclear, probably also buggy, and most importantly, never used.
I've also added a unit test for the `BLI_path_frame_strip` function.
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 77b137a9d6d..6d69f29a228 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -862,7 +862,7 @@ bool BLI_path_frame_get(char *path, int *r_frame, int *r_numdigits) return false; } -void BLI_path_frame_strip(char *path, bool set_frame_char, char *ext) +void BLI_path_frame_strip(char *path, char *r_ext) { if (*path) { char *file = (char *)BLI_last_slash(path); @@ -896,16 +896,14 @@ void BLI_path_frame_strip(char *path, bool set_frame_char, char *ext) c++; - if (numdigits) { - /* replace the number with the suffix and terminate the string */ - while (numdigits--) { - *ext++ = *suffix; - *c++ = set_frame_char ? '#' : *suffix; - suffix++; - } - *c = '\0'; - *ext = '\0'; + int suffix_length = len - (suffix - file); + BLI_strncpy(r_ext, suffix, suffix_length+1); + + /* replace the number with the suffix and terminate the string */ + while (numdigits--) { + *c++ = '#'; } + *c = '\0'; } } |