]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
utf8: export encode_utf8() and decode_utf8()
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 16 Jul 2014 23:05:58 +0000 (16:05 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Fri, 18 Jul 2014 17:45:57 +0000 (10:45 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/common/utf8.c
src/common/utf8.h

index d8e085391981ab9577e89ddecf65155c06f67dd1..5bf0a5be8508574d6876d0d28e17ca8e88a72257 100644 (file)
@@ -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;
index a25fe21b5c166b122b496be347e4f0ac2b7ef30b..28649effaec436c18e1ea27d42b7cea67bb32221 100644 (file)
@@ -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