[FFmpeg-devel] [PATCH] lavu/avstring: add av_get_utf8() function
Stefano Sabatini
stefasab at gmail.com
Thu Oct 3 01:23:47 CEST 2013
TODO: minor bump, APIchanges entry
---
libavutil/avstring.c | 25 +++++++++++++++++++++++++
libavutil/avstring.h | 10 ++++++++++
2 files changed, 35 insertions(+)
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index eed58fa..4be88e7 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -307,6 +307,31 @@ int av_isxdigit(int c)
return av_isdigit(c) || (c >= 'a' && c <= 'f');
}
+int av_get_utf8(int32_t *code, const uint8_t **buf, int flags)
+{
+ const uint8_t *p = *buf;
+ uint32_t top;
+
+ *code = *p++;
+
+ top = (*code & 128) >> 1;
+ if ((*code & 0xc0) == 0x80 || *code >= 0xFE)
+ return AVERROR(EINVAL);
+ *buf = p;
+
+ while (*code & top) {
+ int tmp = *p++ - 128;
+ if (tmp>>6)
+ return AVERROR(EINVAL);
+ *code = (*code<<6) + tmp;
+ top <<= 5;
+ }
+ *code &= (top << 1) - 1;
+
+ *buf = p;
+ return 0;
+}
+
#ifdef TEST
int main(void)
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 438ef79..bd1f722 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -22,6 +22,7 @@
#define AVUTIL_AVSTRING_H
#include <stddef.h>
+#include <stdint.h>
#include "attributes.h"
/**
@@ -226,6 +227,15 @@ static inline int av_tolower(int c)
int av_isxdigit(int c);
/**
+ * Read an UTF-8 character from buffer in *buf, and update *buf to point to the
+ * next sequence after the found character.
+ *
+ * @return >= 0 in case a sequence was successfully read, a negative
+ * value in case of invalid sequence
+ */
+int av_get_utf8(int32_t *code, const uint8_t **buf, int flags);
+
+/**
* Locale-independent case-insensitive compare.
* @note This means only ASCII-range characters are case-insensitive
*/
--
1.8.1.2
More information about the ffmpeg-devel
mailing list