From d027ff1b432a265ad49ddfeafab45093bcd03e6c Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 16 Jul 2014 16:05:58 -0700 Subject: [PATCH] utf8: export encode_utf8() and decode_utf8() Signed-off-by: Yehuda Sadeh (cherry picked from commit 49fc68cf8c3122c878ea9503c9c74d7046bc9c6f) --- src/common/utf8.c | 4 ++-- src/common/utf8.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/common/utf8.c b/src/common/utf8.c index d8e085391981a..5bf0a5be85085 100644 --- a/src/common/utf8.c +++ b/src/common/utf8.c @@ -35,7 +35,7 @@ static int high_bits_set(int c) * Assumes buf is of size MAX_UTF8_SZ * Returns -1 on failure; number of bytes in the encoded value otherwise. */ -static int encode_utf8(unsigned long u, unsigned char *buf) +int encode_utf8(unsigned long u, unsigned char *buf) { int i; unsigned long max_val[MAX_UTF8_SZ] = { @@ -74,7 +74,7 @@ static int encode_utf8(unsigned long u, unsigned char *buf) * Decode a UTF8 character from an array of bytes. Return character code. * Upon error, return INVALID_UTF8_CHAR. */ -static unsigned long decode_utf8(unsigned char *buf, int nbytes) +unsigned long decode_utf8(unsigned char *buf, int nbytes) { unsigned long code; int i, j; diff --git a/src/common/utf8.h b/src/common/utf8.h index a25fe21b5c166..28649effaec43 100644 --- a/src/common/utf8.h +++ b/src/common/utf8.h @@ -44,6 +44,18 @@ int check_for_control_characters(const char *buf, int len); */ int check_for_control_characters_cstr(const char *buf); +/* Encode a 31-bit UTF8 code point to 'buf'. + * Assumes buf is of size MAX_UTF8_SZ + * Returns -1 on failure; number of bytes in the encoded value otherwise. + */ +int encode_utf8(unsigned long u, unsigned char *buf); + +/* + * Decode a UTF8 character from an array of bytes. Return character code. + * Upon error, return INVALID_UTF8_CHAR. + */ +unsigned long decode_utf8(unsigned char *buf, int nbytes); + #ifdef __cplusplus } #endif -- 2.39.5