mirror of https://github.com/mpv-player/mpv
common: add mp_tag_str() utility function
This commit is contained in:
parent
a1f949d3b8
commit
994459e4ce
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "talloc.h"
|
#include "talloc.h"
|
||||||
#include "misc/bstr.h"
|
#include "misc/bstr.h"
|
||||||
|
#include "misc/ctype.h"
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
|
|
||||||
#define appendf(ptr, ...) \
|
#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);
|
av_strerror(AVERROR(errnum), buf, buf_size);
|
||||||
return buf;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
char *mp_strerror_buf(char *buf, size_t buf_size, int errnum);
|
||||||
#define mp_strerror(e) mp_strerror_buf((char[80]){0}, 80, e)
|
#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 */
|
#endif /* MPLAYER_MPCOMMON_H */
|
||||||
|
|
Loading…
Reference in New Issue