diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-06-30 07:47:31 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-06-30 07:47:31 +0300 |
commit | 8bef305b6d6628d9d0cd9b8e8765108842fddc5b (patch) | |
tree | bb364cf7a6e7b1cffe6d3ae6dcd10584097b0354 /source/blender/blenlib | |
parent | 56ca7f34dd602208880a41de6923fa71ebf83a29 (diff) |
Cleanup: move BLI_timestr to BLI_timecode
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_timecode.h | 12 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 16 | ||||
-rw-r--r-- | source/blender/blenlib/intern/timecode.c | 30 |
4 files changed, 39 insertions, 20 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index c8491f4c8f1..1fea42ec922 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -78,7 +78,6 @@ int BLI_natstrcmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_N int BLI_strcmp_ignore_pad(const char *str1, const char *str2, const char pad) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -void BLI_timestr(double _time, char *str, size_t maxlen) ATTR_NONNULL(); void BLI_ascii_strtolower(char *str, const size_t len) ATTR_NONNULL(); void BLI_ascii_strtoupper(char *str, const size_t len) ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_timecode.h b/source/blender/blenlib/BLI_timecode.h index b6cd0117bf5..8f88b555095 100644 --- a/source/blender/blenlib/BLI_timecode.h +++ b/source/blender/blenlib/BLI_timecode.h @@ -31,11 +31,19 @@ * \ingroup BLI */ +#include "BLI_compiler_attrs.h" + size_t BLI_timecode_string_from_time( char *str, const size_t len, const int power, const float time_seconds, - const double scene_fps, const short timecode_style); + const double scene_fps, const short timecode_style) + ATTR_NONNULL(); size_t BLI_timecode_string_from_time_simple( - char *str, const size_t len, const int power, const float time_seconds); + char *str, size_t maxlen, double time_seconds) + ATTR_NONNULL(); + +size_t BLI_timecode_string_from_time_seconds( + char *str, const size_t len, const int power, const float time_seconds) + ATTR_NONNULL(); #endif /* __BLI_TIMECODE_H__ */ diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 3177bc659b2..f846183b082 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -701,22 +701,6 @@ int BLI_strcmp_ignore_pad(const char *str1, const char *str2, const char pad) } } -void BLI_timestr(double _time, char *str, size_t maxlen) -{ - /* format 00:00:00.00 (hr:min:sec) string has to be 12 long */ - int hr = ( (int) _time) / (60 * 60); - int min = (((int) _time) / 60 ) % 60; - int sec = ( (int) _time) % 60; - int hun = ( (int) (_time * 100.0)) % 100; - - if (hr) { - BLI_snprintf(str, maxlen, "%.2d:%.2d:%.2d.%.2d", hr, min, sec, hun); - } - else { - BLI_snprintf(str, maxlen, "%.2d:%.2d.%.2d", min, sec, hun); - } -} - /* determine the length of a fixed-size string */ size_t BLI_strnlen(const char *s, const size_t maxlen) { diff --git a/source/blender/blenlib/intern/timecode.c b/source/blender/blenlib/intern/timecode.c index 39ffbcd7ebe..4ae9249ec0d 100644 --- a/source/blender/blenlib/intern/timecode.c +++ b/source/blender/blenlib/intern/timecode.c @@ -187,6 +187,34 @@ size_t BLI_timecode_string_from_time( return rlen; } +/** + * Generate time string and store in \a str + * + * \param str: destination string + * \param maxncpy: maximum number of characters to copy ``sizeof(str)`` + * \param time_seconds: time total time in seconds + * \return length of \a str + */ +size_t BLI_timecode_string_from_time_simple( + char *str, const size_t maxncpy, const double time_seconds) +{ + size_t rlen; + + /* format 00:00:00.00 (hr:min:sec) string has to be 12 long */ + const int hr = ( (int) time_seconds) / (60 * 60); + const int min = (((int) time_seconds) / 60 ) % 60; + const int sec = ( (int) time_seconds) % 60; + const int hun = ( (int) (time_seconds * 100.0)) % 100; + + if (hr) { + rlen = BLI_snprintf(str, maxncpy, "%.2d:%.2d:%.2d.%.2d", hr, min, sec, hun); + } + else { + rlen = BLI_snprintf(str, maxncpy, "%.2d:%.2d.%.2d", min, sec, hun); + } + + return rlen; +} /** * Generate time string and store in \a str @@ -200,7 +228,7 @@ size_t BLI_timecode_string_from_time( * * \note in some cases this is used to print non-seconds values. */ -size_t BLI_timecode_string_from_time_simple( +size_t BLI_timecode_string_from_time_seconds( char *str, const size_t maxncpy, const int power, const float time_seconds) { size_t rlen; |