summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-01-11 14:35:56 +0100
committerwm4 <wm4@nowhere>2016-01-11 16:24:11 +0100
commit994459e4cedf5cced518820f531b75feb521bea1 (patch)
tree0a779cf03a8b1d2058e0b0e998acf2afa6f6a183
parenta1f949d3b83224306e099c7d670f11eb8f249b84 (diff)
downloadmpv-994459e4cedf5cced518820f531b75feb521bea1.tar.bz2
mpv-994459e4cedf5cced518820f531b75feb521bea1.tar.xz
common: add mp_tag_str() utility function
-rw-r--r--common/common.c17
-rw-r--r--common/common.h3
2 files changed, 20 insertions, 0 deletions
diff --git a/common/common.c b/common/common.c
index c943235c2a..7a651e9781 100644
--- a/common/common.c
+++ b/common/common.c
@@ -23,6 +23,7 @@
#include "talloc.h"
#include "misc/bstr.h"
+#include "misc/ctype.h"
#include "common/common.h"
#define appendf(ptr, ...) \
@@ -258,3 +259,19 @@ char *mp_strerror_buf(char *buf, size_t buf_size, int errnum)
av_strerror(AVERROR(errnum), buf, buf_size);
return buf;
}
+
+char *mp_tag_str_buf(char *buf, size_t buf_size, uint32_t tag)
+{
+ if (buf_size < 1)
+ return buf;
+ buf[0] = '\0';
+ for (int n = 0; n < 4; n++) {
+ uint8_t val = (tag >> (n * 8)) & 0xFF;
+ if (mp_isalnum(val) || val == '_' || val == ' ') {
+ mp_snprintf_cat(buf, buf_size, "%c", val);
+ } else {
+ mp_snprintf_cat(buf, buf_size, "[%d]", val);
+ }
+ }
+ return buf;
+}
diff --git a/common/common.h b/common/common.h
index 7312b85ec8..920ad76a56 100644
--- a/common/common.h
+++ b/common/common.h
@@ -90,4 +90,7 @@ bool mp_append_escaped_string(void *talloc_ctx, struct bstr *dst,
char *mp_strerror_buf(char *buf, size_t buf_size, int errnum);
#define mp_strerror(e) mp_strerror_buf((char[80]){0}, 80, e)
+char *mp_tag_str_buf(char *buf, size_t buf_size, uint32_t tag);
+#define mp_tag_str(t) mp_tag_str_buf((char[22]){0}, 22, t)
+
#endif /* MPLAYER_MPCOMMON_H */